Beryllium
Beryllium

Reputation: 113

Set range to end of column in Vba?

I have a very simple problem that is kind of annoying me. I want to set a variable to a range in excel, where the last row is always different.

Set d = Worksheets("sheet1").Range(("A3":Range("A3".End(xlDown))))

I have tried different variations of this, but none seem to work. The range is on a different worksheet, if that causes any issues.

Is there a simple way to solve this?

Upvotes: 0

Views: 5381

Answers (1)

Mikku
Mikku

Reputation: 6654

Use this:

With Worksheets("sheet1")

Set d = .Range("A3:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)

End With

Upvotes: 2

Related Questions