Activecell.formula variable column number issue

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
434
Office Version
  1. 365
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
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.
 
Upvote 0
What columns should it look at?
 
Upvote 0
How do you determine which columns each time the code is run?
 
Upvote 0
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
 
Upvote 0
That's only one column, is it for E2 or AF2 & what is the other meant to be?
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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