0

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)
  • 1
    https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba – BigBen Jan 27 '21 at 14:05
  • Do you want to **include** values beyond HV in the count if they exist? If so, try `Set countRange = Range("U7", Cells(7, Columns.Count).End(xlToLeft))` – Super Symmetry Jan 27 '21 at 14:33
  • 1
    @SuperSymmetry this is exactly what I wanted to do, just did not know how to set it. – Дробац Jan 28 '21 at 11:39

1 Answers1

1

@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.