Forum Discussion
Logaraj Sekar
Apr 18, 2018Iron Contributor
How to Select Range using VBA?
Hello everyone,
I have values in "Column AD" & "Column AF" from First row. Row count changes everyday in both column.
I'm doing manual selection for both column (eg. Range("AD2:AD53,AF2:AF46")) and putting conditional formatting to find duplicate values. I don't want to select entire column.
I want to select these ranges by macro depends on row count. I tried in macro by,
a=53
b=46
Range("AD2:AD"&a, "AF2:AF"&b).select -> is not working.
Suggestions, ideas are welcome.
Hi Logaraj,
Please try this macro:
Sub SpecificSelection()
Dim ColAD As String
ColAD = "AD1:" & "AD" & Range("AD1048567").End(xlUp).Row
Dim ColAF As String
ColAF = "AF1:" & "AF" & Range("AF1048567").End(xlUp).Row
Dim ColsAD_AF As String
ColsAD_AF = ColAD & "," & ColAF
Range(ColsAD_AF).Select
End SubI hope this helps you
Haytham
1 Reply
- Haytham AmairahSilver Contributor
Hi Logaraj,
Please try this macro:
Sub SpecificSelection()
Dim ColAD As String
ColAD = "AD1:" & "AD" & Range("AD1048567").End(xlUp).Row
Dim ColAF As String
ColAF = "AF1:" & "AF" & Range("AF1048567").End(xlUp).Row
Dim ColsAD_AF As String
ColsAD_AF = ColAD & "," & ColAF
Range(ColsAD_AF).Select
End SubI hope this helps you
Haytham