Can't get macro to run correctly

courtneyd112

New Member
Joined
Apr 21, 2011
Messages
6
Good morning -
I have written a macro that works correctly ONLY when I click on the cell that the macro starts in. If I try to run the macro if a random cell is selected, it wont run correctly. How can I get the macro to run the same everytime regardless of which cell is selected? Thank you!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the forums!

Can you please post the code you are currently using, as well as what cell you want it to start from?
 
Upvote 0
ActiveCell.FormulaR1C1 = "SUPD"
Range("E1").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[5]C[-2]:R[77]C[-2],""SUPD"")"
Range("D2").Select
ActiveCell.FormulaR1C1 = "SUPQ"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[4]C[-2]:R[73]C[-2],""SUPQ"")"
Range("D3").Select
ActiveCell.FormulaR1C1 = "SYKQ"
Range("E3").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[3]C[-2]:R[82]C[-2],""SYKQ"")"
Range("D4").Select
ActiveCell.FormulaR1C1 = "SYKP"
Range("E4").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[2]C[-2]:R[72]C[-2],""SYKP"")"
Range("D5").Select




Want it to start in D1
 
Upvote 0
yes, always want it to start in D1 - regardless of what cell is selected on the page

i didn't use relative references.
 
Upvote 0
Try:
Code:
Range("D1") = "SUPD"
Range("E1").FormulaR1C1 = "=COUNTIF(R[5]C[-2]:R[77]C[-2],""SUPD"")"
Range("D2")= "SUPQ"
Range("E2").FormulaR1C1 = "=COUNTIF(R[4]C[-2]:R[73]C[-2],""SUPQ"")"
Range("D3") = "SYKQ"
Range("E3").FormulaR1C1 = "=COUNTIF(R[3]C[-2]:R[82]C[-2],""SYKQ"")"
Range("D4") = "SYKP"
Range("E4") .FormulaR1C1 = "=COUNTIF(R[2]C[-2]:R[72]C[-2],""SYKP"")"
Range("D5").Select
 
Upvote 0
PHP:
[d1] = "SUPD"
[E1] = "=COUNTIF(R[5]C[-2]:R[77]C[-2],""SUPD"")"
[D2] = "SUPQ"
[E2] = "=COUNTIF(R[4]C[-2]:R[73]C[-2],""SUPQ"")"
[D3] = "SYKQ"
[E3] = "=COUNTIF(R[3]C[-2]:R[82]C[-2],""SYKQ"")"
[D4] = "SYKP"
[E4] = "=COUNTIF(R[2]C[-2]:R[72]C[-2],""SYKP"")"

you forgot to tell it to start at D1
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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