Forum Discussion

Logaraj Sekar's avatar
Logaraj Sekar
Iron Contributor
Apr 18, 2018
Solved

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 Sub

     

    I hope this helps you

    Haytham 

1 Reply

  • Haytham Amairah's avatar
    Haytham Amairah
    Silver 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 Sub

     

    I hope this helps you

    Haytham 

Resources