I have multiple cells containing text data and would like to replace some data with data from another sheet.
Example
Sheet 1
A1= "aa*a"
B1= "b]bb"
C1= "cae*"
Sheet 2
A1="q" B1="Quote"
A2="e" B2="Example"
Result
A1
stays the same, B1
stays the same and C1
changes to caExample*
I guess I need an VBA code for a find and replace with an VLookUp
.
Can anybody help me out?
Give this a try:
Sub PolyChange()
Dim s1 As Worksheet, s2 As Worksheet
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
Dim I As Long, J As Long, v1 As String
Dim N1 As Long, N2 As Long, v2 As String, v3 As String
N1 = s1.Cells(Rows.Count, "A").End(xlUp).Row
N2 = s2.Cells(Rows.Count, "A").End(xlUp).Row
For I = 1 To N1
v1 = s1.Cells(I, "A")
For J = 1 To N2
v2 = s2.Cells(J, "A")
v3 = s2.Cells(J, "B")
v1 = Replace(v1, v2, v3)
Next J
s1.Cells(I, "A").Value = v1
Next I
End Sub
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.