VBA: using string from an Input Box as criteria for a CountIF

downsy

New Member
Joined
Aug 19, 2014
Messages
2
Hi all

I'm trying to enter text (a staff members initials) into an Input Box so that the initials are then used as the citeria in a CountIF formula entered by VBA

A simplified version of the code I am using is:

Dim staffname As String
staffname = InputBox(Prompt:="You name please.", _
Title:="ENTER INITIALS", Default:="MC")

Range("H9").FormulaR1C1 = "=COUNTIF(RC[-3]:RC[-1],"" & staffname & "")"

The issue is getting the staffname string to be entered within the formula.

What is the correct combination of "" & to enable this to work.

Many thanks in advance for any advice offered.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
Range("H9").FormulaR1C1 = "=COUNTIF(RC[-3]:RC[-1],""" & staffname & """)"
 
Upvote 0
thanks Scott, that looks remarkably like a variation I thought I tried - but obviously not!

works perfectly
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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