Harshil Mehta
Board Regular
- Joined
- May 14, 2020
- Messages
- 85
- Office Version
- 2013
- Platform
- Windows
The code finds a match for the each cells in Sheet2_Column_1 from Sheet1_Column_1....If a match is found then replace the range in Sheet2_Columns_1 to 5 with Sheet1_Columns_7 to 11.
The blow code only replaces the cell data in Sheet2_Column_1 with Sheet1_Column_7 when the match is found.
Is there any way I could replace all the other column data at once?
The blow code only replaces the cell data in Sheet2_Column_1 with Sheet1_Column_7 when the match is found.
Is there any way I could replace all the other column data at once?
VBA Code:
Sub Replace_range()
Dim Cl As Range
Dim Dic As Object
Set Dic = CreateObject("scripting.dictionary")
With Sheets("Sheet1")
For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
Dic(Cl.Value) = Cl.Offset(, 6)
Next Cl
End With
With Sheets("Sheet2")
For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
If Dic.exists(Cl.Value) Then
Cl.Value = Dic(Cl.Value)
End If
Next Cl
End With
End Sub