比较VBA中的两列

时间:2016-03-25 19:58:56

标签: vba excel-vba excel

我应该下载一个包含客户ID(约100)的工作表(称之为第一个工作簿)。我们有一个不同的工作簿(工作簿2),其中包含所有客户ID和这些客户的名称。我想将工作簿1中的客户ID转换为基于第二个工作簿的预期名称。到目前为止,我认为我有一个相当不错的基础,但我已经调试了一堵墙。我们欢迎所有的建议!

Option Explicit

Sub getcompanyname()

Dim wsll As Worksheet
Dim wsd As Workbook

Dim c As Range
Dim d As Range

Dim lastRow2 As Integer
lastRow2 = Workbooks("MatchWerks Customer Quick Reference.xlsx").Worksheets("Sheet1").UsedRange.Rows.Count

Dim lastRow As Integer
lastRow = ActiveSheet.UsedRange.Rows.Count

Set wsd = Workbooks.Open("C:\Users\Dylan Hoffman\Documents\SugarSync Shared Folders\Support\Customer Support\MatchWerks Customer Quick Reference.xlsx")
Set wsll = ThisWorkbook.Worksheets("customtableitem_customtable_mbs")

For Each c In ThisWorkbook.Worksheets("customtableitem_customtable_mbs").Columns("C1:C" & lastRow).Cells

    For Each d In Workbooks("MatchWerks Customer Quick Reference.xlsx").Worksheets("Sheet1").Columns("A3:A" & lastRow2).Cells
    If c = d Then
    c = d.Offset(0, 1)
    End If
    Next d
Next c

End Sub

1 个答案:

答案 0 :(得分:0)

基本上您正在尝试使用查询来获取数据。您应该在此response

中看到相关示例