Match column data for 400 lines of data...Help!

ksmith

New Member
Joined
Oct 8, 2002
Messages
49
Please look at the code below...as you can see I am matching data in column A with column B.....A1 to B1, A2 to B2, etc....and then when the data doesn't match it displays an error box and doesn't go any further.........only problem with the way i know how to do it is, I dont want to copy this code 400 times for 400 lines of data.......I know there's a much better way.....can anyone help??!!??

THANKS!
Kyle :rolleyes:


Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Sheets("data").Select
Dim msg As String

Range("a3").Select
If ActiveCell.Value <> Range("b3").Value Then
msg = "Problem starting at " & ActiveCell.Value & " on data."
MsgBox msg

Else
Range("a4").Select
If ActiveCell.Value <> Range("b4").Value Then
msg = "Problem starting at " & ActiveCell.Value & " on data."
MsgBox msg

Else
Range("a5").Select
If ActiveCell.Value <> Range("b5").Value Then
msg = "Problem starting at " & ActiveCell.Value & " on data."
MsgBox msg
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
Sub matchcells() 'by WillR

Sheets("Sheet1").Select
For x = 1 To 400
If Cells(x, 1).Value = Cells(x, 2).Value Then
With Cells(x, 1).Interior
        .ColorIndex = 3
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
   End With
End If
Next x

End Sub

This code will format all the cells in column A that match the same row in col B Red..... Might help - would save all those error boxes popping up....
 
Upvote 0
Thank you very much!.......I modified it just a bit, but that headed me right where I wanted to go.

Thanks Again! :D
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,336
Members
451,697
Latest member
pedroDH

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