|
我想用EXECL VBA 写一段代码,工作表名称有“工程”字样的工作表中第2行中某个单元格内容与工作表“项目费用统计“第2行某个单元格内容相一致时,则名称有“工程”字样的工作表对应单元格所在的那一列第8行中单元格内容复制到工作表“项目费用统计”中对应单元格所在列的第4行单元格,自第4行依次往下填写。
代码如下:
Sub ExtractData() Dim ws1 As Worksheet Dim ws2 As Worksheet Dim i As Integer Dim j As Integer Dim k As Integer k = 4 For Each ws1 In ThisWorkbook.Worksheets If InStr(ws1.Name, "工程") > 0 Then For i = 2 To ws1.UsedRange.Rows.Count For Each ws2 In ThisWorkbook.Worksheets If ws2.Name = "项目费用统计" Then For j = 8 To ws1.UsedRange.Columns.Count If ws1.Cells(2, j).Value = ws2.Cells(2, j).Value Then ws2.Cells(k, j).Value = ws1.Cells(8, j).Value End If Next End If Next k = k + 1 Next End If NextEnd Sub
实际运行后,变成了这样
我的实际想法是变成这样的
|
|