Share via

Reference a range using a variable

Anonymous
2016-08-30T20:38:45+00:00

Hello

I have data in columns with various number of rows.

I know the data starts at row 10 but the ending row is unknown.

I create a variable, Stuff, and  build the range that I need to select.

How can I use my variable, Stuff, to select the data range?

IT seems that I should be able to use: Range("Stuff").Select but this does not work.

Thanks for looking.

Sample code

Sub Macro2()

'

' Macro2 Macro

'

Dim Stuff As Long

Dim Stuff1 As Range

'

    Range("C9").Select

    Stuff = "C10"

    Selection.End(xlDown).Select

    Stuff = Stuff & ":C" & ActiveCell.Row     'Stuff now contains "C10:C108"

         'Range("Stuff").Select                                     'Does not work

         'Set Stuff1 = ("Stuff")                                      'Does not work

    Stuff1.Select                                                         'Does not work

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-08-30T20:45:16+00:00

Hi,

A valiant effort but try it like this. NOTE. It is extremely unlikely that you actually need to select the range to do what you want.

Sub somesub()

Dim Stuff As Long

Stuff = Cells(Cells.Rows.Count, "C").End(xlUp).Row

Range("C10:C" & Stuff).Select

End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-08-30T23:48:27+00:00

    Thank you!!

    That worked.

    You are correct, I did not need to select the range first.

    I was able to copy a formula and .paste to the range.

    Thanks again.

    Was this answer helpful?

    0 comments No comments