Simple CountIf VBA

beginvbaanalyst

Board Regular
Joined
Jan 28, 2020
Messages
139
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'd like to transfer this macro recorder into an unlimited cell countif in cell E2.
I don't see where my value in "a2" is being recorded?
Range("E2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=COUNTIF(C[2],RC[-4])"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E159")
Range("E2:E159").Select
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Can you please explain what you are trying to do?
At the moment your code is putting a countif formula into E2:E159
 
Upvote 0
I would like the VBA to do a countif as
=COUNTIF(G:G,E2)
The data would be put into "F2" and then dropped down to the last filled cell.
 
Upvote 0
How about
VBA Code:
   Range("F2:F" & Range("G" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=countifs(c[1],rc[-1])"
 
Upvote 0
How about
VBA Code:
   Range("F2:F" & Range("G" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=countifs(c[1],rc[-1])"

Hi Fluff,

For some reason it's just inserting "countifs(c[1],rc[-1])" into each cell.
1593789189236.png


What's the reason this could be happening?
I'm trying to check to see if the data in column G is in Column E using F2 as my start point.
 
Last edited:
Upvote 0
Can you please post your code using code tags, the <vba/> icon in the reply window.
Also check that column F isn't formatted as text.
 
Upvote 0
Can you please post your code using code tags, the <vba/> icon in the reply window.
Also check that column F isn't formatted as text.
VBA Code:
 Range("F2:F" & Range("G" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "COUNTIF(C[1],RC[-1])"

I can confirm Column F isn't formatted as text.
 
Upvote 0
You've removed the = sign from the formula.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,540
Members
449,038
Latest member
Guest1337

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