"countif" in multiple worksheets using VBA

romelsms1

New Member
Joined
Mar 25, 2011
Messages
4
Hi all,

I’m truing to create a macro for “counting” cells that contain a particular character in multiple worksheets ( “X” in my case)
All my sheets have the same pattern (except the first which is a analysis sheet) so I have the same tables in the same position (but different inputs)

I made ​​a macro that works but only if place the “cell” in the code (first example) :
Function numara_daca()
Application.Volatile
mylast = Worksheets.Count
For j = 2 To mylast
With Worksheets(j)
If UCase(.Range("C11")) = "X" Then
numara_daca = numara_daca + 1
End If
End With
Next j
End Function


so if i enter in a cell from my worksheet =numara_daca() only works for cell C11 and here is my problem: I want to apply macro across multiple cells without having to enter them each time in the code. I wish I could enter it in cell function like this =numara_daca(C11) or =numara_daca(D12) or something like that


I tried to create a code....but does not work...gives me: #VALUE!
Function numara_daca1(cell As Range)
Application.Volatile
mylast = Worksheets.Count
For j = 2 To mylast
With Worksheets(j)
If UCase(.Range(cell)) = "X" Then
numara_daca1 = numara_daca1 + 1
End If
End With
Next j
End Function


any idea???
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
Function numara_daca1(cell As Range)
    Application.Volatile
    Dim ws As Worksheet
    For Each ws In Worksheets
        If UCase(ws.Range(cell.Address)) = "X" Then numara_daca1 = numara_daca1 + 1
    Next ws
End Function
 
Upvote 0

Forum statistics

Threads
1,220,933
Messages
6,156,937
Members
451,386
Latest member
leolagoon94

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