Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

VBA - Refer to a Column in Cell

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA - Refer to a Column in Cell

    Columns("DD:DI").Select
    Selection.FillRight

    But I want to make it dynamic where DD and DI are listed in cells say A1 and A2. How do I convert the syntax to reference the cells?

    Thank you in advance! I am super bad at syntax... I tired Columns(Range("A1") & ":" & Range("A2")).Select

  • #2
    Re: VBA - Refer to a Column in Cell

    Hi toofxd, and welcome to the forum!
    You were close. Need to specify that you wanted the values from those ranges. Could do this in one step, but spacing it out for visibility
    Code:
    Sub ExampleCode()
        Dim firstCol As String
        Dim secCol As String
        
        'What cells are our controls in?
        firstCol = Range("A1").Value
        secCol = Range("A2").Value
        
        'Use that info to build our range string
        Range(firstCol & ":" & secCol).FillRight
    End Sub
    Best Regards,
    Luke M
    =======
    "A little knowledge is a dangerous thing."

    Comment

    Trending

    Collapse

    There are no results that meet this criteria.

    Working...
    X