Comapring Values In Two Rnages Of Cells

Dawid2005

New Member
Joined
Jun 10, 2011
Messages
3
Good Day All

I am very new to VBA coding as well as this forum and enjoying the experience and the possibilities of what it can do immensely.

I however came across a bit of a snag and I would like some help with it.

What I need is a macro that compares values of Cells B4 to the end of data wich can be C4 or even J4, the ranges is not always the same, this must be compared to the values of Cells B4 to the end of data the same applies as above the number of colomns is not always the same, to undertsand this better.
I need to compare the values in cells B4 lets say to J4 with the values in Cells B29 to lets say H4.

The end value will not always be in the same colomn, but the start values will always be in B4 and B29.

I hope this all makes sense.

Any help will be appreciated.

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Sorry I am not sure how to attache a file here but what I mean by saying comapare is that it must look if the values in each cell of the two ranges is the same if it is not the same I want to trigger another macro(This Part I have figured out).

The part I am looking for is a Macro to check each Cells in the ranges and see if it is the same.

A simple example is

Cells: B4 B5 B6 B7 B7
Values 11 131 140 72 81
Compare with
Cells B29 B30 B31 B32
Values 11 140 72 81

The Result I want is that Range B4:B7 will stay the same but Range B29:B32 will end up look like this

Cells B29 B30 B31 B32 B33
Values 11 Empty 140 72 81

Hope this makes more sense.

Thanks
 
Upvote 0
So, if I right understand, values being compared are in the same column?
Then try this.
Code:
Sub CompareByColumns()

    Dim i As Long
    Dim rng1 As Range, rng2 As Range
    
    Set rng1 = Range("B4", Range("B4").End(xlToRight))
    Set rng2 = Range("B29", Range("B29").End(xlToRight))
    
    For i = 1 To rng1.Count
        If rng1(i) <> rng2(i) Then rng2(i).ClearContents
    Next

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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