Creating Loop for Entire Used Range across all sheets

HSAR

Banned - Rules violations
Joined
Jul 6, 2020
Messages
37
Office Version
  1. 2016
Platform
  1. Windows
Hi, Team Mrexcel i am new here.

I have been using this below code to count colored cell right now this is just counting colored cell for single column. If i add two or more ranges then its answer would be same rather then different.

I want you to modify this code so that code will count all used range. For Example if it is count Column "J" then result should be mentioned in J1 & if it is count Column "K" then result should be mentioned in K1
and so on till used range.

I am not expecting for formula created by VBA. Please do help.

VBA Code:
Public Sub CountColorCells()
 Dim rng As Range
 Dim lColorCounter As Long
 Dim rngCell As Range
 Set rng = Sheet2.Range("J2:J20")
 For Each rngCell In rng
 If Cells(rngCell.Row, rngCell.Column).DisplayFormat.Interior.Color = RGB(183, 225, 205) Then
 lColorCounter = lColorCounter + 1
 End If
 Next
 Sheet2.Range("J1") = lColorCounter
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

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