Reputation: 217
I have a data set that looks like this:
Pin
I am trying to loop through this and replace parts of each cell with a different designation. Here is the code I have so far:
Dim CompPin() As String
Dim AutoPin() As String
Dim Item As Variant
CompPin() = Split("1ARD 2ARD 1RPI 2RPI")
AutoPin() = Split("PB1A PC1A PF1A PF2B")
For Each Item In CompPin
Worksheets("Demo").Columns("D").Replace What:=CompPin(Item), Replacement:=AutoPin(Item), LookAt:=xlPart
Next
When I run this code, I get a type mismatch. Any insight would be helpful.
Upvotes: 0
Views: 96
Reputation: 29421
an alternative could be a "double-split":
Sub main()
Dim CompAutoPin() As String
Dim Item As Variant
CompAutoPin() = Split("1ARD-PB1A 2ARD-PC1A 1RPI-PF1A 2RPI-PF2B")
For Each Item In CompAutoPin
Worksheets("Demo").Columns("D").Replace What:=Split(Item, "-")(0), Replacement:=Split(Item, "-")(1), LookAt:=xlPart
Next Item
End Sub
Upvotes: 0
Reputation: 1221
Try this
CompPin() = Split("1ARD 2ARD 1RPI 2RPI")
AutoPin() = Split("PB1A PC1A PF1A PF2B")
For n = 0 To UBound(CompPin)
Worksheets("Demo").Columns("D").Replace What:=CompPin(n), Replacement:=AutoPin(n), LookAt:=xlPart
Next
Upvotes: 2