有2个文件。输入文件(.xlsb格式)和代码文件。
在代码文件中,我想要一个 VBA 代码,其中 Excel 要求 xlsb 格式的输入文件位置。
在输入文件的 CL 列中应用 Vlookup ** =VLOOKUP(CONCAT(U2,V2,AJ2,AK2,AL2),[代码文件.xlsx]Sheet99'!$D:$Q,14,0) ** 直到输入文件 D 列的行末尾。
一旦完成。消息框应显示为“完成”。
请帮忙。
我尝试了以下代码:
子流程数据() 将输入文件变暗为字符串 调暗 wb 作为工作簿 调暗 wsData 作为工作表 调暗 wsMap 作为工作表 调暗最后一行只要 昏暗我只要
' Ask for input file path
inputFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls; *.xlsx; *.xlsb), *.xls; *.xlsx; *.xlsb", Title:="Select Input File")
' Exit if user cancels the file selection
If inputFile = "False" Then
Exit Sub
End If
' Open the input file
Set wb = Workbooks.Open(inputFile)
Set wsData = wb.Sheets(1) ' Assuming the data is in the first sheet
' Find the last row with data in column D
lastRow = wsData.Cells(wsData.Rows.Count, "D").End(xlUp).Row
' Concatenate values in CL column
For i = 2 To lastRow
wsData.Cells(i, "CL").Value = wsData.Cells(i, "U").Value & _
wsData.Cells(i, "V").Value & _
wsData.Cells(i, "AJ").Value & _
wsData.Cells(i, "AK").Value & _
wsData.Cells(i, "AL").Value
Next i
' Fetch information from 'Sheet99' sheet
Set wsMap = ThisWorkbook.Sheets("Sheet99")
For i = 2 To lastRow
' Assuming the data in 'Micro Segment Map' sheet starts from row 2
wsData.Cells(i, "CM").Value = Application.VLookup(wsData.Cells(i, "CL").Value, wsMap.Range("D:Q"), 14, False)
Next i
' Display "Done" message
MsgBox "Done"
结束子