Excel Sheet Sheet1中的值与Sheet2中的值进行比较
我有一个Excel电子表格,其中有2个工作表。 在列AI中的第一个工作表中有一个存储名称。 第二个工作表是工作表1的一个子集,也有存储名称,但它们位于工作表2的列B中。我需要将工作表1中的每个存储名称(列A)与工作表中的每个存储名称(列B)进行比较2并提取2相交(具有相同的店名)。 到目前为止,我已经在VB中完成了以下操作:
Sub RunMe() Dim lRow, x As Long Sheets("Sheet1").Select lRow = Range("A2").End(xlDown).Row For Each cell In Range("B2:B" & lRow) x = 2 Do If cell.Value = Sheets("Sheet1").Cells(x, "A").Value Then cell.EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) End If x = x + 1 Loop Until IsEmpty(Sheets("Sheet1").Cells(x, "A")) Next End Sub
我如何修改上面的代码来比较工作表1的每个存储名称(列A)到工作表2的每个存储名称(列B)?
尝试这个
Sub RunMe() Dim cell1 As Range, cell2 As Range Dim rng1 As Range, rng2 As Range Set rng1 = GetRange("Sheet1",1) Set rng2 = GetRange("Sheet2",2) For Each cell2 In rng2 For Each cell1 In rng1 If cell1.Value = cell2.Value Then cell2.EntireRow.Copy Worksheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) End If Next Next End Sub Function GetRange(shtName As String, colIndex as Long) As Range With Worksheets(shtName) Set GetRange = .Range(.Cells(2, colIndex), .Cells(.Rows.Count, colIndex).End(xlUp)) End With End Function
- 拼写检查并获取下一个单元格中的build议列表
- 在Firefox浏览器中输出dynamic的HTML表格,使其在JavaScript中performance突出
- Excel Vba获取单元格的值并设置一个string
- 在Microsoft Excel中打开select并从ASP.NET Web窗体应用程序发回到服务器。 服务器上没有SharePoint
- Oracle服务器错误 – “命名pipe道提供程序,错误:40 – 无法打开连接到SQL Server”
- 数字格式化为文本,同时将剑道网格导出为excel
- 在ASP.NET Linq数据绑定中将GridView数据导出到Excel
- VBA – 处理Javascript自动popupIE浏览器
- Excel – macrosselect当前date的工作簿中的单元格