简体   繁体   中英

Comparing two columns in VBA

I am supposed to download a worksheet (call it the first workbook) that contains customer Ids (about 100). We have a different workbook (workbook2) that contains all of the customer Ids and the names of those customers. I would like to translate those customer Ids from workbook1 into their prospective names based on the second workbook. I think I have a pretty decent foundation so far but I have hit a wall with debugging. Any suggestions would be much appreciated!

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

Basically you are trying to fetch data with a query. You should see a sample for this in this response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM