Дробац
Дробац

Reputation: 11

VBA Set range from cell to last column with value

I have set range from cell "U7" to "HV7". Purpose of this range is to count values in it.

Current code is working, but I would like to escape possibility of values beyond HV column, by selecting to last value.

Dim countRange As Range
Set countRange = Range("U7:HV7")

Dim rowcount As Long
rowcount = Application.WorksheetFunction.CountA(countRange)

Upvotes: 0

Views: 547

Answers (1)

Дробац
Дробац

Reputation: 11

@SuperSymmetry provided me with desired solution.

Set countRange = Range("U7", Cells(7, Columns.Count).End(xlToLeft)

Values in my table are proper formatted so I could with this solution select all from cell U7 to the last value on the right.

Upvotes: 1

Related Questions