Hello!
The following code produces a "Compile error:Object required". However, i don't see where an argument might be missing. I tried the same code without the 'Dim' and 'Set' (when are they required anyway? i have no clue...), then i get a "ByRef type mismatch" error.
Can anyone help? I guess from the above questions it became clear that i am a beginner (for VBA, not otherwise). Please explain why the error happens and what's the correct way to fix it. Please do no completely rewrite the code, because in that case i probably will not learn the lesson that is hidden in this error.
The error happens in this line:
Set itemCount = WorksheetFunction.CountA(.Range(axesTab & "!$A$2:$A$1000"))
However, if i remove the 'Set', the error moves a little forward to
Set Export = .Cells(itemRow, 4).Value
Remove that 'Set' and the error moves to
Set faAction = .Cells(itemRow, 3).Value
Remove this 'Set' and the error change to the type mismatch on 'faAxis' in this line:
Call addFlexibleAxisItem(csvTab, faAxis, faItem, faAction)
Questions:
-What do these error messages mean?
-Why do these errors appear?
-Why do they appear on itemCount, Export and faAction, but not on faItem or faAxis?
-Is there an easy solution to the problem?
Thank you,
Hinnerk
Code:
Sub enlistAxes(csvTab As String, axesTab As String)
Dim faItem, faAxis, faAction As String
Dim currentLine, itemRow, itemCount As Integer
Dim Export As Boolean
Set currentLine = lastLine(csvTab) + 2
With ActiveWorkbook.Worksheets(axesTab)
Set itemCount = WorksheetFunction.CountA(.Range(axesTab & "!$A$2:$A$1000"))
For itemRow = 2 To (itemCount + 1)
Set Export = .Cells(itemRow, 4).Value
If Export Then
Set faItem = .Cells(itemRow, 1).Value
Set faAxis = .Cells(itemRow, 2).Value
Set faAction = .Cells(itemRow, 3).Value
Call addFlexibleAxisItem(csvTab, faAxis, faItem, faAction)
Set currentLine = currentLine + 2
End If
Next itemRow
End With
End Sub
Sub addFlexibleAxisItem(csvTab As String, Axis As String, Item As String, Action As String)
currentLine = lastLine(csvTab) + 2
Range(csvTab & "!A" & currentLine).Value = "Axis=" & Axis
Range(csvTab & "!B" & currentLine).Value = "Item=" & Item
Range(csvTab & "!C" & currentLine).Value = "Action=" & Action
End Sub
Function lastLine(DataSheet As String)
lastLine = ActiveWorkbook.Worksheets(DataSheet).Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Row
End Function
Bookmarks