This is not finished code - I am trying soemthing out and using this as my test example - I have soem code which I want to able to run against any sheet - so I need to pass in the sheet that I want the code to run against; this is the code I have;
If I replace the 'pSheet' part of the code with "Sheet1" - it all works as expected (I do have a Sheet1)- if I call it like this;
Call Test("Sheet1") or Test(Sheet1) I get an error 'subscript out of range'
I have been through many (many) itereations of trying to get this to work - I have used a String variable to pass the name I have tried assigning the worksheet to a variable like this;
Dim ws As Worksheet
Set ws = Worksheet("Sheet1")
Call Test(ws) or Call Test("ws")
all to no avail. I obviously have something very wrong with my syntax (and probably my understanding of it) - what can I do to pass in 'any' worksheet to run the code against here ?
Thanks very much for reading.
VBA Code:
Sub Test(pSheet As Worksheet) ' SEEMS TO WORK EVEN AFTER DELETING SOME DATA
Dim c As Long, r As Long, iStr As String
c = pSheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
r = pSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
iStr = Replace(Cells(r, c).Address, "$", "") ' Address with no "$"
MsgBox iStr
End Sub
If I replace the 'pSheet' part of the code with "Sheet1" - it all works as expected (I do have a Sheet1)- if I call it like this;
Call Test("Sheet1") or Test(Sheet1) I get an error 'subscript out of range'
I have been through many (many) itereations of trying to get this to work - I have used a String variable to pass the name I have tried assigning the worksheet to a variable like this;
Dim ws As Worksheet
Set ws = Worksheet("Sheet1")
Call Test(ws) or Call Test("ws")
all to no avail. I obviously have something very wrong with my syntax (and probably my understanding of it) - what can I do to pass in 'any' worksheet to run the code against here ?
Thanks very much for reading.