Forum Discussion
hrh_dash
May 18, 2022Iron Contributor
Is there a way to have a dynamic textjoin with IF condition lookup from another workbook VBA
I tried to create a vba code for this but was unsuccessful, hopefully i could get some help from here. Sub join()
Dim ws As Worksheet
Dim exportWb As Workbook
Dim exportWs As Worksheet
Set expo...
- May 19, 2022
Sorry
Sub join() Dim ws As Worksheet Dim exportWb As Workbook Dim exportWs As Worksheet Dim exportlastRow As Long Set ws = Sheet1 Set exportWb = Workbooks.Open("C:\Users\desktop\export.xlsx") Set exportWs = exportWb.Sheets("Sheet1") exportlastRow = exportWs.Cells(exportWs.Rows.Count, "E").End(xlUp).Row ThisWorkbook.Activate ws.Range("C10") = ws.Evaluate("TEXTJOIN("", "",TRUE,IF([export.XLSX]Sheet1!E2:E" & _ exportlastRow & "=C15,[export.XLSX]Sheet1!A2:A" & exportlastRow & ",""""))") End Sub
hrh_dash
May 19, 2022Iron Contributor
HansVogelaar , vba is showing an error - "Run-time error '91' Object variable or with block variable not set
Should i have 2 exportlastRow1 and exportlastRow2 as i have 2 different columns; A and E?
and
Should the C15 be right after IF function?
Dim exportlastRow1 As Range
Dim exportlastRow2 As Range
Set exportlastRow1 = exportWs.Cells(exportWs.Rows.Count, "E").End(xlUp).Row
Set exportlastRow2 = exportWs.Cells(exportWs.Rows.Count, "A").End(xlUp).Row
ws.Range("C10") = ws.Evaluate("TEXTJOIN("", "",TRUE,IF(C15 = [export.XLSX]Sheet1!E2:E" & _
exportlastRow1 & ",[export.XLSX]Sheet1!A2:A" & exportlastRow2 & ",""""))")
HansVogelaar
May 19, 2022MVP
Sorry
Sub join()
Dim ws As Worksheet
Dim exportWb As Workbook
Dim exportWs As Worksheet
Dim exportlastRow As Long
Set ws = Sheet1
Set exportWb = Workbooks.Open("C:\Users\desktop\export.xlsx")
Set exportWs = exportWb.Sheets("Sheet1")
exportlastRow = exportWs.Cells(exportWs.Rows.Count, "E").End(xlUp).Row
ThisWorkbook.Activate
ws.Range("C10") = ws.Evaluate("TEXTJOIN("", "",TRUE,IF([export.XLSX]Sheet1!E2:E" & _
exportlastRow & "=C15,[export.XLSX]Sheet1!A2:A" & exportlastRow & ",""""))")
End Sub
- hrh_dashMay 22, 2022Iron Contributorthe code does not seemed to have any difference as compared to the earlier code..
- HansVogelaarMay 22, 2022MVP
The variable exportlastRow was declared as a Range, now as a Long.
- hrh_dashMay 22, 2022Iron Contributor
HansVogelaar , it is still showing an error: "Run-time error '1004': Application-defined or object-defined error
- HansVogelaarMay 22, 2022MVP
Which line causes the error?
- hrh_dashMay 22, 2022Iron Contributor
HansVogelaar , first line is throwing out the error