How to set a column as a range variable as long as there is data in it

0 votes

I would like excel to input the entire column with the title "Section" into the range variable 'sectioncol'.

Set sectioncol = range(range("A1:R1").Find(what:="Section", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Address & ":" & range("A1:R1").Find(what:="Section", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).End(xlDown).Address)

I was expecting the range variable to return the cells containing data under the section column.

Feb 16, 2023 in Others by Kithuzzz
• 38,000 points
616 views

1 answer to this question.

0 votes

Try this:

Dim rng As Range
Set rng = Range("A1:R1").Find( _
    What:="Section", LookIn:=xlValues, _
    LookAt:=xlWhole, MatchCase:=False)

If Not rng Is Nothing Then ' Test if Section was found
    Dim sectioncol As Range
    Set sectioncol = Range(rng, Cells(Rows.Count, rng.Column).End(xlUp))
End If
answered Feb 16, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
4,681 views
0 votes
1 answer

Is there any way in python to auto-correct spelling mistake in multiple rows of an excel files of a single column?

Use Spellchecker for doing your stuff: import pandas ...READ MORE

answered Oct 14, 2022 in Others by narikkadan
• 63,600 points
2,059 views
0 votes
1 answer

Is there a way to quickly check what attribute the data is in a cell in a spreadsheet?

Excel will automatically make assumptions about the ...READ MORE

answered Jan 8, 2023 in Others by narikkadan
• 63,600 points
546 views
0 votes
1 answer

Is there a way to test a formula result in excel and type it only once, all within one cell and not using a user defined function?

Use the Let function: =LET(Value,A1+B2+C4+G3+B4,IF(Value>10,"No",Value)) I hope this helps ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
666 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,218 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,668 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
916 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,058 views
0 votes
1 answer

How to check if a cell is empty in a range variable?

Use WorksheetFunction.CountA() (https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.counta) function If WorksheetFunction.CountA(rng) = 0 Then ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,600 points
837 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,723 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP