Selecting Range in VBA (easy for you guys)

Curtisyoung78

New Member
Joined
Jun 19, 2017
Messages
25
I have this code to compare two sheets that will bold the differences between the sheets, the problem is i only want to compare from column A:Q and from row 12 down to infinity. And not the used range as specified in the code below.

Hope someone can help thanks in advance.



Sub RunCompare()


Call compareSheets("REV0", "REV1")


End Sub




Sub compareSheets(shtREV0 As String, shtREV1 As String)


Dim mycell As Range
Dim mydiffs As Integer

For Each mycell In ActiveWorkbook.Worksheets(shtREV1).UsedRange 'here I need it to look at column A:Q and from row 12 down to infinity
If Not mycell.Value = ActiveWorkbook.Worksheets(shtREV0).Cells(mycell.Row, mycell.Column).Value Then

mycell.Font.Bold = True
mydiffs = mydiffs + 1

End If
Next




ActiveWorkbook.Sheets(shtREV1).Select


End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Assuming you will always have data in Column "A"

Code:
Dim lRow as Long

lRow = Worksheets(shtREV1).Cells(Rows.Count, 1).End(xlUp).Row

ActiveWorkbook.Worksheets(shtREV1).range("A12:Q"& lRow).value
 
Upvote 0
Code:
Sub compareSheets(shtREV0 As String, shtREV1 As String)
  Dim wks0          As Worksheet
  Dim wks1          As Worksheet
  Dim cell          As Range

  Set wks0 = Worksheets(shtREV0)
  Set wks1 = Worksheets(shtREV1)

  For Each cell In Intersect(wks1.UsedRange, wks1.Range("A:Q"))
    If cell.Value <> wks0.Range(cell.Address).Value Then
      cell.Font.Bold = True
    End If
  Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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