Adding condition to an If statement,

dannyjoer

New Member
Joined
Oct 21, 2013
Messages
7
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:

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!
smile.gif


Danny
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top