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 you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Lets try this again! Its the last two lines that are the important bits!

VBA Code:
''Match First Text to derive first column
    Sheets("Pivot Data").Select
Cells.Find(What:="Test 1", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
Test1Column = ActiveCell.Column

''Match Second Text to derive second column
Cells.Find(What:="Test 2", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
Test2Column = ActiveCell.Column

'''This is the cell that I need the formula to be put into
Range("A2").Select

'''This is the formula that needs to go into the cell - HOWEVER - E2 should be linked in to Test1Column, row 2 & AF2 should be linked in to Test2Column, row 2
    ActiveCell.Formula = "=COUNTIFS(E2,"">=""&Utilities!$F$12,AF2,"">""&Utilities!$H$12)"

Please let me know if this is any clearer.. or not!
 
Last edited:
Upvote 0
Thanks for that, how about
VBA Code:
ActiveCell.FormulaR1C1 = "=and(rc" & test1column & ">=Utilities!r12c6,rc" & test2column & ">Utilities!r12c8)+0"
 
Upvote 0
Solution

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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