Check if first word in each row of range matches another range

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,199
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have two ranges
Sheets("Data").range("A1:A36")
and
Sheets("RawData").range("D1:D36")


Now what I want to do is check if the first word or each row in Sheets("Data").range("A1:A36") matches the first word of the same row in Sheets("RawData").range("D1:D36")

Now if All words match then

msgbox "All good"

if not then

message box

"There are some unmatch errors"

please help if you can

Thanks
Tony
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
NB test on a COPY of your work, first!

VBA Code:
Sub comp()

Dim rng_dta As Worksheet
Dim rng_rwdta As Worksheet
Dim intgr As Integer

Set rng_dta = Sheets("Data")
Set rng_rwdta = Sheets("RawData")

intgr = 1

        Do Until intgr = 37
            If rng_dta.Range("A" & intgr) <> rng_rwdta.Range("A" & intgr) Then GoTo failmess
            intgr = intgr + 1
           
        Loop
    Pass = MsgBox("All good", 64, "Match")
Exit Sub
failmess: Fail = MsgBox("One or more cells don't match blah blah", 64, "Mismatch")
End Sub
 
Upvote 0
Pleasure, and thanks for the feedback.

The only thing I've noticed is that you originally asked for the test to be on the FIRST WORD in each row, and my suggestion only tests the whole cell's value.
This means that my suggestion will throw the "error" message if a first word matches, but a second word is different. Do you actually need this, or is my original solution sufficient?
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,311
Members
449,308
Latest member
Ronaldj

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