JPARKHURST
Board Regular
- Joined
- Oct 25, 2016
- Messages
- 151
I continue to have problems getting the hang of VBA's structure (my fault, I've not taken the time to run though some lessons properly, been running and grabbing just to get certain parts working).
The following gives me a byRef argument type mismatch. The last section is my call, and it is returning the error. For the life of me, I can't see what I have done. I have gone through and marked everything I can as public, in case it wasn't able to see a definition, I will turn that off by sections as able.
What am I missing? I declare the wsWorkingDispatch as a worksheet in the general, on workbook open I set it to the appropriate sheet, then I feed it to a sub which calls for a worksheet, so I'm missing something.
I can replace this with sheets(workingdispatch), but that's not ideal - I'd like to know what I am missing here if anybody can help. TIA!
===============General Declarations====================
Option Explicit
Public wbThis As Workbook
Public wsDashboard As Worksheet
Public wsWorkingDispatch As Worksheet
Public wsJobDispatch As Worksheet
Public wsShortages As Worksheet
===============Workbook====================
Public Sub Workbook_Open()
Set wbThis = ThisWorkbook
Set wsDashboard = Sheets("Dashboard")
Set wsWorkingDispatch = Sheets("Working_Dispatch")
Set wsJobDispatch = Sheets("Job_Dispatch")
Set wsShortages = Sheets("Shortages")
End Sub
===============Module1====================
Public Sub ClearEm(wsClear As Worksheet)
Dim lrow As Long
Dim clRange As Range
Dim cpRange As rnage
wsClear.Active
lrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
MsgBox (lrow)
Set clRange = wsClear.Range("A1:S" & lrow)
MsgBox (lrow + 1)
Set cpRange = wsClear.Range("A" & lrow + 1 & ":S" & lrow + 1)
End Sub
===============Button--> Sub Call====================
Public Sub btnClearRangeWD_Click()
Call ClearEm(wsWorkingDispatch)
End Sub
Thank you,
Jon
The following gives me a byRef argument type mismatch. The last section is my call, and it is returning the error. For the life of me, I can't see what I have done. I have gone through and marked everything I can as public, in case it wasn't able to see a definition, I will turn that off by sections as able.
What am I missing? I declare the wsWorkingDispatch as a worksheet in the general, on workbook open I set it to the appropriate sheet, then I feed it to a sub which calls for a worksheet, so I'm missing something.
I can replace this with sheets(workingdispatch), but that's not ideal - I'd like to know what I am missing here if anybody can help. TIA!
===============General Declarations====================
Option Explicit
Public wbThis As Workbook
Public wsDashboard As Worksheet
Public wsWorkingDispatch As Worksheet
Public wsJobDispatch As Worksheet
Public wsShortages As Worksheet
===============Workbook====================
Public Sub Workbook_Open()
Set wbThis = ThisWorkbook
Set wsDashboard = Sheets("Dashboard")
Set wsWorkingDispatch = Sheets("Working_Dispatch")
Set wsJobDispatch = Sheets("Job_Dispatch")
Set wsShortages = Sheets("Shortages")
End Sub
===============Module1====================
Public Sub ClearEm(wsClear As Worksheet)
Dim lrow As Long
Dim clRange As Range
Dim cpRange As rnage
wsClear.Active
lrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
MsgBox (lrow)
Set clRange = wsClear.Range("A1:S" & lrow)
MsgBox (lrow + 1)
Set cpRange = wsClear.Range("A" & lrow + 1 & ":S" & lrow + 1)
End Sub
===============Button--> Sub Call====================
Public Sub btnClearRangeWD_Click()
Call ClearEm(wsWorkingDispatch)
End Sub
Thank you,
Jon