I am trying to learn how to pass values back and forth between subs. I have created several macro subs that ultimately use the same lines of code over and over again between them. To start I want to be able to look up/count the # of columns and rows. This is what I have so far but it is not working.
I would also like to expand it beyond just cols to rows.
Public Sub main()
Dim lCols As Integer
Dim lRows As Integer
lCols = countCols(Sheet1)
Sheet1.Range("M2").Value = lCols
End Sub
Public Function countCols(sheetValue As Worksheet) As Variant
countCols = sheetValue.Cells(Rows.Count, 1).End(x1Up).Row
Exit Function
End Function
Right now it hangs within the function... Appears it is not passing the "Sheet1" into sheetValue.