VBA Formula to Check if the Range between blank rows are the same and loop

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
272
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I need your advice if possible.

I have a dataset which i am trying to determine between blank rows with variable blocks of data ranges in Column R to see if the numerical values are the same within the range and if the value are the same I want "True" and where its not exact "False" value all the way down in the range.

I have tried with the below code and I cant get past the below code as I get a : Run-time error '1004': Application or object-defined error

.Formula = "=AND(EXACT(" & Rng.Offset(, 1).Address(0, 0) & ")"

This is the code I am using.

Sub CHECK_RANGE()
Dim Rng As Range

For Each Rng In Range("R2", Range("R" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
With Rng.Offset(Rng.Count, 1).Resize(1, 7)
.Formula = "=AND(EXACT(" & Rng.Offset(, 1).Address(0, 0) & ")"
.Value = .Value
End With
Next Rng

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Apologies I forgot to attach a screen shot of my data set so you can see what I am doing in column R and trying to achieve in column V.
 

Attachments

  • Screenshot 2023-02-09 221920.jpg
    Screenshot 2023-02-09 221920.jpg
    26 KB · Views: 9
Upvote 0
VBA Code:
Sub LoopArea()

Dim lr As Long

Dim area As Range

Dim sh As Worksheet

Set sh = ActiveSheet

lr = sh.Cells(Rows.Count, "R").End(xlUp).Row

'Constant based Area in Col R

For Each area In sh.Range("R2:R" & lr).SpecialCells(xlCellTypeConstants, 23).Areas

area.Interior.Color = vbGreen

area(1,3).value = WorksheetFunction.Countif(area,area(1,1)) <> area.cells.count

Next area

End Sub
 
Last edited by a moderator:
Upvote 0
Solution
@VBA learner ITG
When posting vba code in the forum, please use the available code tags, not quote tags.
My signature block below has more details. I have changed the tags for you this time in post 3. 😊
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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