Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I've written some code here, aided by the extremely helpful user Jeeped. Only problem is that I'm getting the error Invalid Procedure Call or Argument when the vlookup does not find a result. If it finds a result, it seems to be fine.
Invalid Procedure Call or Argument
I want it to just return #N/As if it can't find a result. Can you help me fix this? Also I have 500 columns to do this with so if there's a much easier way to write it to account for that, that'd be great. I'm still learning VBA. Thanks so much.
Dim v As Long, vWSs As Variant, Mrange As Range, Vrange As Range Dim wsMaster As Worksheet: Set wsMaster = Workbooks("LBImportMacroTemplate.xlsm").Worksheets("MasterTab") Dim mf_iA_TEXT As String: mf_iA_TEXT = "iA" Dim mf_pLN_TEXT As String: mf_pLN_TEXT = "pLN" 'ET CETERA vWSs = Array("B", "E", "L", "I", "T") With Workbooks("LBImportMacroTemplate.xlsm") Set Mrange = Nothing: Set Vrange = Nothing ' With ActiveSheet lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row MsgBox lastrow End With ' For v = LBound(vWSs) To UBound(vWSs) If CBool(Application.CountIf(.Sheets(vWSs(v)).Range("A2:ZA2"), mf_iA_TEXT)) Then Set Mrange = .Sheets(vWSs(v)).Range("A2:ZA2") Set Vrange = .Sheets(vWSs(v)).Range("A:ZA") mf_iA = Application.Match(mf_iA_TEXT, Mrange, 0) Exit For End If Next v For i = 2 To lastrow wsMaster.Cells(i, 2) = Application.VLookup(wsMaster.Cells(i, 1), Vrange, mf_iA, 0) Next i Set Mrange = Nothing Set Vrange = Nothing ' For v = LBound(vWSs) To UBound( REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
Your VLookup statements will fail with the described error message if the VRange object is nothing.
VLookup
VRange
It's difficult to understand what you're trying to do but I will try to break it down. Here you have a loop that exits on the first instance of the CBool expression returning True.
CBool
True
For v = LBound(vWSs) To UBound(vWSs) If CBool(Application.CountIf(.Sheets(vWSs(v)).Range("A2:ZA2"), mf_iA_TEXT)) Then Set Mrange = .Sheets(vWSs(v)).Range("A2:ZA2") Set Vrange = .Sheets(vWSs(v)).Range("A:ZA") mf_iA = Application.Match(mf_iA_TEXT, Mrange, 0) Exit For End If Next v
At this point assuming the loop is exited by the Exit For statement, the VRange object should exist and be a valid range, so the next loop should not fail:
Exit For
For i = 2 To lastrow wsMaster.Cells(i, 2) = Application.VLookup(wsMaster.Cells(i, 1), Vrange, mf_iA, 0) Next i
HOWEVER if that first loop completes without ever "finding" the value mf_iA_Text, then the VRangeobject is not a valid range, and that would cause the error.
mf_iA_Text
Suggest to revise by putting the second loop inside the first:
For v = LBound(vWSs) To UBound(vWSs) If CBool(Application.CountIf(.Sheets(vWSs(v)).Range("A2:ZA2"), mf_iA_TEXT)) Then Set Mrange = .Sheets(vWSs(v)).Range("A2:ZA2") Set Vrange = .Sheets(vWSs(v)).Range("A:ZA") mf_iA = Application.Match(mf_iA_TEXT, Mrange, 0) For i = 2 To lastrow wsMaster.Cells(i, 2) = Application.VLookup(wsMaster. REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.