K
kayetter
I am new to excel programming. I am attempting to replace the values i
column b of sheet 1 with a corresponding value from sheet 2. I wan
the program to look at a value in column 1 of sheet 1, then find th
same value in column 1 of sheet 2. Then take the corresponding valu
from column 2 of sheet 2 and bring it into column 2 of sheet 1.
Here is what I have tried so far:
Sub Replace_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
Dim hold As String
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through.
iListCount = Sheets("sheet1").Range("A1:A10").Rows.Count
' Loop through the "master" list.
For Each x In Sheets("Sheet1").Range("A1:A10")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet2").Cells(iCtr, 1).Value Then
hold = Sheets("Sheet2").Cells(iCtr, 2)
Sheets("Sheet1").Cells(iCtr, 2) = hold
' Increment counter to account for next row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Su
column b of sheet 1 with a corresponding value from sheet 2. I wan
the program to look at a value in column 1 of sheet 1, then find th
same value in column 1 of sheet 2. Then take the corresponding valu
from column 2 of sheet 2 and bring it into column 2 of sheet 1.
Here is what I have tried so far:
Sub Replace_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
Dim hold As String
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through.
iListCount = Sheets("sheet1").Range("A1:A10").Rows.Count
' Loop through the "master" list.
For Each x In Sheets("Sheet1").Range("A1:A10")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet2").Cells(iCtr, 1).Value Then
hold = Sheets("Sheet2").Cells(iCtr, 2)
Sheets("Sheet1").Cells(iCtr, 2) = hold
' Increment counter to account for next row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Su