VBA Counter that sets itself to the number a specifc word appears in a sheet when excel is opened.

FelixExcel

New Member
Joined
Sep 14, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hey all, Im currently working on an excel project in which I use a counter. Right now I use following code to reset the counter to 0 everytime excel is opened.

Private Sub UserForm_Initialize()

counter = 0

End Sub


I now noticed that this is actually not what I need. I would need the counter to set itself to the number a specific word, for example "hello" appears in my excel sheet. I have a feeling there is an easy solution to this, which shouldnt involve to many lines of code.

So far I made a bit of progress and found out that I can use the formular =SUMIF(range, "Text") to count how often a certain word appears in a certain range, but Im not sure how Im able to integrate this number into my vba code. Is there an option to just set my counter to the value of the cell that has the sumif formular. For example if the formular would be in the cell A2:

Private Sub UserForm_Initialize()

counter = A2

End Sub


I would appreciate any help with this.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
@FelixExcel If you have the desired count value in a specific cell then code will be along these lines...

VBA Code:
counter = ThisWorkbook.Sheets("Edit To Suit").Range("A2")
Hope that helps.
 
Upvote 0
Hey all, Im currently working on an excel project in which I use a counter. Right now I use following code to reset the counter to 0 everytime excel is opened.

Private Sub UserForm_Initialize()

counter = 0

End Sub


I now noticed that this is actually not what I need. I would need the counter to set itself to the number a specific word, for example "hello" appears in my excel sheet. I have a feeling there is an easy solution to this, which shouldnt involve to many lines of code.

So far I made a bit of progress and found out that I can use the formular =SUMIF(range, "Text") to count how often a certain word appears in a certain range, but Im not sure how Im able to integrate this number into my vba code. Is there an option to just set my counter to the value of the cell that has the sumif formular. For example if the formular would be in the cell A2:

Private Sub UserForm_Initialize()

counter = A2

End Sub


I would appreciate any help with this.
Meant to say COUNTIF instead of SUMIF
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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