Comparing two sheets. All columns?

Sladhued

New Member
Joined
Aug 4, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
The code below are for comparing two diffrent sheets in one workbook. it compares rows in column A, and it works excelent. Do anyone know how to make it compare rows through all columns (A-M), and not just A? appriciate any help.

Sub Compare()
Dim LR As Long
Dim x As Range
Dim xr As Range

Application.ScreenUpdating = False

LR = Cells(Rows.Count, 1).End(3).Row

Sheets("Ny").Columns("N:N").Insert Shift:=xlToRight

Set xr = Sheets("Ny").Range("N2:N" & LR)

With xr

.Formula = "=IF(ISNA(VLOOKUP(A2,Aktuell!$A$2:$M$2000,1,false)),""Bold"","""")"
.Value = .Value

End With

For Each x In xr

If x.Value = "Bold" Then x.EntireRow.Font.Bold = True

Next

Sheets("Ny").Columns("N:N").Delete Shift:=xlToLeft



Application.ScreenUpdating = True

End Sub
 
You have multiple rows with the same values in col A, how is a macro meant to know which row it should look at?
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You have multiple rows with the same values in col A, how is a macro meant to know which row it should look at?
I had the same thought as you. I actually didnt think it was possible until I found an Excel plug-in that could do exactly that, its called synkronizer.

I actually made it work now though, with this code:
VBA Code:
Sub Compare()
Dim LR As Long
Dim x As Range
Dim xr As Range

Application.ScreenUpdating = False

LR = Cells(Rows.Count, 1).End(3).Row

Set xr = Sheets("Ny").Range("N2:N" & LR)

With xr
       
        .Formula = "=IF(ISNA(VLOOKUP(A2,Aktuell!$A$2:$M$2000,1,false)),""Bold"","""")"
        .Value = .Value
   
End With

For Each x In xr

    If x.Value = "Bold" Then x.EntireRow.Font.Bold = True
   
Next

Sheets("Ny").Columns("N:N").Delete Shift:=xlToLeft



Application.ScreenUpdating = True

End Sub

and then i add a section of:
VBA Code:
Set xr = Sheets("Ny").Range("N2:N" & LR)

With xr
       
        .Formula = "=IF(ISNA(VLOOKUP(A2,Aktuell!$A$2:$M$2000,1,false)),""Bold"","""")" 'change the A:s to whatever column you want to compare
        .Value = .Value
   
End With

For Each x In xr

    If x.Value = "Bold" Then x.EntireRow.Font.Bold = True
   
Next

Sheets("Ny").Columns("N:N").Delete Shift:=xlToLeft
for every column I want to compare. So it looks something like this:
VBA Code:
Sub Compare()
Dim LR As Long
Dim x As Range
Dim xr As Range

Application.ScreenUpdating = False

LR = Cells(Rows.Count, 1).End(3).Row

Set xr = Sheets("Ny").Range("N2:N" & LR)

With xr
       
        .Formula = "=IF(ISNA(VLOOKUP(A2,Aktuell!$A$2:$M$2000,1,false)),""Bold"","""")"
        .Value = .Value
   
End With

For Each x In xr

    If x.Value = "Bold" Then x.EntireRow.Font.Bold = True
   
Next

Sheets("Ny").Columns("N:N").Delete Shift:=xlToLeft
Set xr = Sheets("Ny").Range("N2:N" & LR)

With xr
       
        .Formula = "=IF(ISNA(VLOOKUP(B2,Aktuell!$B$2:$M$2000,1,false)),""Bold"","""")" 'change the A:s to whatever column you want to compare
        .Value = .Value
   
End With

For Each x In xr

    If x.Value = "Bold" Then x.EntireRow.Font.Bold = True
   
Next

Sheets("Ny").Columns("N:N").Delete Shift:=xlToLeft



Application.ScreenUpdating = True

End Sub

Not entirely sure how its working, but it does.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
Okay I have to open this topic again.

the code i have is unreliable, it sometimes misses some rows. Don't know why.

Do anyone have any ideá?

This SHOULD be possible, the app "Synkronizer" can do this without problem, like this:
 

Attachments

  • excel-compare-jump-to-difference.jpg
    excel-compare-jump-to-difference.jpg
    159.2 KB · Views: 8
Upvote 0

Forum statistics

Threads
1,223,933
Messages
6,175,481
Members
452,647
Latest member
MatthewBiersay

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