I cannot get my code to properly identify the last column with data. The Last Column should be $Q$9
but when running the function I get $M$9
as my Last Column. What am I doing wrong?
Code
Function Q3calls()
Set wb = ActiveWorkbook
Set ws = wb.Sheets("clientmenu")
lastrow = ws.Range("M" & ws.Rows.Count).End(xlUp).Row
lastcol = ws.Cells(8, Columns.Count).End(xlToLeft).Column
With ws
Set rng = .Range(.Cells(8, 13), .Cells(lastrow, lastcol))
End With
Q3calls = Application.WorksheetFunction.CountIfs(rng, ">=" & wb.Sheets("sheet1").Range("A67"), rng, "<=" & wb.Sheets("Sheet1").Range("B67")) 'q3
Exit Function
End Function
Screen Shot of Range