Hi guys
I am working on a search and replace macro. It's purpose is that within a region that varies only in row size, it's suppose to compare two
values, A and B. THey are placed in two adjacent columns. A is only placed in one cell in the region, while B is a one column range in the region.
If A <> B, A should replace all B's in the region.
These regions are placed on top of each other in a long table. Another table is then placent adjacent to that table and so on.
The code I am using is this:
The problem is if the B value in the next region is the same as the one before but the A value change, my code don't pick up on it, because it only looks for changing B!
How can I expand the code to also pick up on this problem?
Any help is very appreciated.
Br. and happy friday!
Danny
I am working on a search and replace macro. It's purpose is that within a region that varies only in row size, it's suppose to compare two
values, A and B. THey are placed in two adjacent columns. A is only placed in one cell in the region, while B is a one column range in the region.
If A <> B, A should replace all B's in the region.
These regions are placed on top of each other in a long table. Another table is then placent adjacent to that table and so on.
The code I am using is this:
Code:
[/COLOR]Sub ReplaceDRW()'Macro created by the courtesy of nilem, Excel Forum
Dim x, i&, j&, s$
With Range("A9").CurrentRegion 'Select starting point, the upper left corner of region
x = .Resize(.Rows.Count + 2).Value
For j = 3 To UBound(x, 2) Step 7
'Step to reach the next set of columns
s = "Plate" 'Initiate S
For i = 1 To UBound(x) - 2
If x(i, j) <> x(i + 1, j) Then
'In initiating case, if x(1, 3) different from x(2, 3)
x(i, j) = s: s = x(i + 2, j - 1)
Else
x(i, j) = s
End If
Next i
Next j
.Value = x
End With
End Sub[COLOR=#333333]
The problem is if the B value in the next region is the same as the one before but the A value change, my code don't pick up on it, because it only looks for changing B!
How can I expand the code to also pick up on this problem?
Any help is very appreciated.
Br. and happy friday!
Danny