很抱歉这不是问这个问题的合适地点。但是,我对应该向谁寻求帮助感到迷茫。我知道我想完成的工作可以使用= IF公式完成。但是,我想看看是否有VBA等效项。
下面是指向电子表格(Concur AX上载副本)和CSV(Concur提取)的驱动器链接。
理论上,如果“ Concur Extract”中的F列中包含“部门”,我希望工作表中标题为“ Concur AX Upload的副本”的列I填充“ LLC”。如果“一致提取”中的F列中包含“属性”,那么我希望工作表中标题为“一致AX上传的副本”的第I列填充“一致提取”中G列中已经给出的值。如果不清楚,对不起! 谢谢!!!
https://drive.google.com/open?id=1NGFdkydLx7gXwLFBpp5bKiZOSsPTqBN1
答案 0 :(得分:0)
我根据两个工作簿编写以下代码。对我来说很好。 请调整工作簿 Concur Extract 20180614.csv 的路径:
Sub test()
'Adapt this path
Dim path_wb_csv As String
path_wb_csv = "C:\test\Concur Extract 20180614.csv"
'Define the workbook
Dim wb As Workbook
Dim wb_csv As Workbook
Set wb = ThisWorkbook
Set wb_csv = Workbooks.Open(path_wb_csv)
'define the sheets that we use
Dim ws As Worksheet
Dim ws_csv As Worksheet
Set ws = wb.Sheets("Expense JE")
Set ws_csv = wb_csv.Sheets("Concur Extract 20180614")
'define le last row
'adapt the column letter to define each last row of work book - I use column A
Dim wb_lastRow As Long
wb_lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 2 To wb_lastRow Step 1
If ws_csv.Cells(i, 6).Value = "Department" Then
ws.Cells(i, 9).Value = "LLC"
ElseIf ws_csv.Cells(i, 6).Value = "Property" Then
ws.Cells(i, 9).Value = ws_csv.Cells(i, 7).Value
End If
Next i
wb_csv.Close
End Sub