Good afternoon, I thought I would post all of my code for this procedure as it might make my question/task more understandable. I would like to know if there is a "better" way of doing what I have done as this seems a little slow and it only has some 1,100 rows to populate.
Basically I have to populate each row in a provided workbook (WB1) with values from a second workbook (WB2) based on the values in a third workbook (WB3). My solution is to identify the row number in WB3 (matching Column "A" in WB1) and then create a formula testing that row's Column "U" and a VLOOKUP to WB2 if the test is true.
Many thanks,
D€$
Basically I have to populate each row in a provided workbook (WB1) with values from a second workbook (WB2) based on the values in a third workbook (WB3). My solution is to identify the row number in WB3 (matching Column "A" in WB1) and then create a formula testing that row's Column "U" and a VLOOKUP to WB2 if the test is true.
Code:
Sub MyOrEO()
Dim Verbfile As String, VerbSheet As String, VerbfileO As String, VerbSheetO As String, MyPath As String, AWB As String
Dim MyRow As Integer, x As Integer
AWB = ActiveWorkbook.Name
MyPath = "G:\DP\LbL\"
Verbfile = "Combined Verbatims V2.xlsx" 'Alternative verbs workbook
VerbSheet = "q23_other_spec"
VerbfileO = "ukc12400397_0 - FINAL DOWNLOAD for Des2.xlsx" 'Original verbs workbook
VerbSheetO = "Verbatim to be cleaned"
If CheckFileIsOpen(VerbfileO) = False Then
Workbooks.Open MyPath & VerbfileO
End If
If CheckFileIsOpen(Verbfile) = False Then
Workbooks.Open MyPath & Verbfile
End If
Workbooks(AWB).Activate
'use cells.rows.count rather than a hard row count value
EndRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
For x = 2 To EndRow
Range("EO" & x).FormulaR1C1 = "= IFERROR(MATCH(RC1,'[" & VerbfileO & "]" & VerbSheetO & "'!C1,""0""),"""")"
If Range("EO" & x).Value <> "" And Range("EO" & x).Value <> "0" Then
MyRow = Range("EO" & x).Value
Range("EO" & x).FormulaR1C1 = _
"=IF(OR('[" & VerbfileO & "]" & VerbSheetO & _
"'!R" & MyRow & "C21 = ""sat_1"" ,'[" & VerbfileO & "]" & VerbSheetO & _
"'!R" & MyRow & "C21 = ""sat_2"" ,'[" & VerbfileO & "]" & VerbSheetO & _
"'!R" & MyRow & "C21 = ""sat_3"" ,'[" & VerbfileO & "]" & VerbSheetO & _
"'!R" & MyRow & "C21 = ""sat_4""),IFERROR(VLOOKUP(RC1,'[" & Verbfile & "]" & VerbSheet & "'!C2:C7,6,0),""""),"""")"
End If 'If Range("EO" & x).Value <> "" Then
Next x
Range(("EO2:EO" & EndRow)).Copy
Range("EO2").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
Many thanks,
D€$