Search code examples
excelvbauserform

Last row of column using the column number


This should be really easy, but I can't see it.

I've several columns, one for each team (over the range shL.Range(S2:AA2)). Below each team is a series of values which should be available in a Userform Listbox, depending on the team which has been selected.

I've got a code which reports the Column number of the team, and I'm trying to find the last row number based on that column. This is causing a Run-Time error 1004 (Method 'Range' of object '_Worksheet' failed), which I expect is caused by shL.Range(Cells( but I'm not seeing how to fix it.

Is there a better way to find the last row of the column?

Dim y As Long, c As Long
Dim shE As Worksheet, shL As Worksheet, FoundTeam As Range
Set shE = Sheets("EnteredData")
Set shL = Sheets("Lookups")

Set FoundTeam = shL.Range("S2:AA2").Find(what:=shE.Range("D3"))
    c = FoundTeam.Column
    y = shL.Range(Cells(3, c) & Rows.Count).End(xlUp).Row

I appreciate any help with this issue. Thanks


Solution

  • Not sure what you are trying to do with the concatenation, but try:

    y = shL.Cells(shL.Rows.Count, c).End(xlUp).Row