Activecell.formula variable column number issue

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
417
Office Version
  1. 2016
Platform
  1. Windows
I have code that places a formula into a cell. What I am looking to do is have variable column numbers for E2 & AF2 as these columns will change.

Rich (BB code):
ActiveCell.Formula = "=COUNTIFS(E2,"">=""&Utilities!$F$12,AF2,"">""&Utilities!$H$12)"

I have the code to work out the column numbers but cant work out how to integrate that into the formula

VBA Code:
Cells.Find(What:="Test Search", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
TestSearchCol = ActiveCell.Column
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
417
Office Version
  1. 2016
Platform
  1. Windows
I have code that places a formula into a cell. What I am looking to do is have variable column numbers for E2 & AF2 as these columns will change.

VBA Code:
ActiveCell.Formula = "=COUNTIFS([B]E[/B]2,"">=""&Utilities!$F$12,[B]AF[/B]2,"">""&Utilities!$H$12)"

I have the code to work out the column numbers but cant work out how to integrate that into the formula

VBA Code:
Cells.Find(What:="Test Search", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
TestSearchCol = ActiveCell.Column
Note the code is actually:

VBA Code:
ActiveCell.Formula = "=COUNTIFS(E2,"">=""&Utilities!$F$12,AF2,"">""&Utilities!$H$12)"

I mistakenly bolded it... and it has added [ B ] in.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,239
Office Version
  1. 365
Platform
  1. Windows
What columns should it look at?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,239
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

How do you determine which columns each time the code is run?
 

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
417
Office Version
  1. 2016
Platform
  1. Windows
How do you determine which columns each time the code is run?
Using the below code
VBA Code:
Cells.Find(What:="Test Search", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
TestSearchCol = ActiveCell.Column
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,239
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

That's only one column, is it for E2 or AF2 & what is the other meant to be?
 

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
417
Office Version
  1. 2016
Platform
  1. Windows
That's only one column, is it for E2 or AF2 & what is the other meant to be?
That's only one column, is it for E2 or AF2 & what is the other meant to be?
VBA Code:
Cells.Find(What:="Test Search1", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
TestSearchCol1 = ActiveCell.Column
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,239
Office Version
  1. 365
Platform
  1. Windows
You have now quoted post#7 twice & your own post, but given no answer.
Please do not quote posts like that it's totally pointless. Just use the "Quick reply window" below the thread.
 

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
417
Office Version
  1. 2016
Platform
  1. Windows
Ive just added a 1 on to the end - its not the same. Call one a and one b. a is searching for test and b is searching for test1. I know how to get the columns, I just don't know how to integrate it into the activecell.formula.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,389
Messages
5,769,798
Members
425,572
Latest member
ja189704

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
Top