VBA Lookup - Unable to get the Vlookup property of the WorkSheet function class
Date : March 29 2020, 07:55 AM
it helps some times I know that a similar problem was already discussed here: Why is VLookup in VBA failing with runtime error 1004? , This might be a shot in the dark but I believe your error is here PosIdent = "IdSelect" & "/" & Cnt + 1
PosIdent = Range("IdSelect").Value & "/" & Cnt + 1
For Cnt = 0 To ServCnt + 1
PosIdent = Range("IdSelect").Value & "/" & Cnt + 1
ActiveCell.Value = Application.WorksheetFunction.VLookup(PosIdent, Data, 15, False)
ActiveCell.Offset(1, 0).Activate
Next Cnt
Option Explicit
Public ServCnt As Integer
Sub Main()
Call Count_Line_Items
Call Count_Total_Rows
Call Write_Services
End Sub
Sub Count_Line_Items()
'Counts the number of line items of a consulting project to determine the space needed on the invoice form
Dim Cell As Range
Dim PosCnt As Integer
Dim ExpCnt As Integer
PosCnt = 0
ServCnt = 0
ExpCnt = 0
'Counting all project positions for the chosen project number
For Each Cell In Range("ProjectList")
If Cell.Value = Range("IdSelect") Then
PosCnt = PosCnt + 1
End If
Next Cell
MsgBox "Total number of line items: " & PosCnt
'Counting all positions of that project that are consulting services
For Each Cell In Range("ProjectList")
If Cell.Value = Range("IdSelect").Value And Cell.Offset(0, 3).Value = "Service" Then
ServCnt = ServCnt + 1
End If
Next Cell
MsgBox "Total number of consulting services: " & ServCnt
'Calculating number of expense items
ExpCnt = PosCnt - ServCnt
MsgBox "Total number of expenses: " & ExpCnt
End Sub
Sub Count_Total_Rows()
Dim Current_RowCnt As Integer
Dim Target_RowCnt As Integer
Dim Diff_Rows As Integer
Target_RowCnt = 62
'Counting the rows in the print area and calculating difference to target
Range("Print_Area").Select
Current_RowCnt = Selection.Rows.Count
Diff_Rows = Target_RowCnt - Current_RowCnt
If Diff_Rows > 0 Then
MsgBox "We need to add " & Diff_Rows & " rows!"
ElseIf Diff_Rows < 0 Then
MsgBox "We need to delete " & -Diff_Rows & " rows!"
Else
MsgBox "Nothing needs to be done; all good!"
End If
End Sub
Sub Write_Services() 'Looks up services on data sheet and writes them to invoice sheet Dim Cnt As Integer Dim PosIdent As String Dim Data As Range
Cnt = 0
'Building position identifier
Sheets("Input").Select
ActiveSheet.Range("D26:AD151").Select
Set Data = Selection
PosIdent = Range("IdSelect").Value & "/" & Cnt + 1
Sheets("Invoice").Select
ActiveSheet.Range("Service_Title").Offset(1, 0).Activate
'There is still an issue with the counter (line number won't increment by 1 if cnt range is incremented by 1
For Cnt = 0 To ServCnt + 1
ActiveCell.Value = Application.WorksheetFunction.VLookup(PosIdent, Data, 15, False)
ActiveCell.Offset(1, 0).Activate
Cnt = Cnt + 1
Next Cnt
End Sub
|
VBA - Unable to get TextBoxes Property of Worksheet Class
Tag : excel , By : christiandsg
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Sorry to answer my own question. Figured it out by accident. The problem was that I had my textbox (txtFilePath) grouped together with another textbox on my worksheet. When I ungrouped them everything worked fine. Can anyone explain to me why the grouping would make a difference?
|
VBA Error Handling: Unable to get the match property of the worksheet function class
Tag : excel , By : Andrew
Date : March 29 2020, 07:55 AM
seems to work fine Error handling in VBA is a bit tricky. Basically, you are handling an error inside your loop, but you did not exit the procedure. You hit the error once, you handle it and you continue the loop - but you are still in the same sub - so the next error will raise regardless of the Error-handling mechanism that you had put in place.. To continue in your same procedure/loop after you caught and handled an error, you need to invoke in any way the Resume statement. After invoking Resume, your Error-Handling mechanism is again valid. In your case, you should do the following: On Error Goto ErrHandler
Do While Sheets("Sheet1").Range("A" & n) <> ""
.... ' your loop
NextN:
n = n + 1
Loop
...
Exit Sub
ErrHandler:
Resume NextN 'you need to call Resume, to continue your loop with valid error handling.
End Sub
|
#ERROR: Unable to get match property of the worksheet class. I have already tried solutions available online
Tag : excel , By : Ryuken
Date : March 29 2020, 07:55 AM
hope this fix your issue a = Application.Small(m, j) will surely return an Error Code when j is actually bigger that the size of te range m. In your code, the range m = Range("E3:E40") has 38 cells, but j can go as high as 38 * 172. Then you try to call Match with an error code as the first parameter a. This resuts in run-time error. Note here that Application.Match would result in an error code while WorksheetFunction.Match raises a run-time error. a = Application.Small(m, k) ' <--- k, not j
|
Error '1004'- Unable to Get Sum Property of the worksheet function Class with defined range variable
Date : March 29 2020, 07:55 AM
To fix the issue you can do For those interested, this code works fine. I was getting an error because I had an #value error in the sum range.
|