Can I modify this VBA formula?

seth777

New Member
Joined
Apr 22, 2016
Messages
9
Here is the VBA formula:
Sub Macro1() ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1],STOCK!R2C1:R19562C10,HLOOKUP(R5C3,STOCK!R1C2:R2C10,2,FALSE),FALSE)"
Range("G6").Select
End Sub


Currently it can only spit out a 1 or a 0 into column G. But if I run it, it only runs for G6. How can I make it loop from G5:G305?

What I really need is for if to color the cell in F green if it is 1 and no fill if it is 0. Is this possible?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hey seth777,

Regarding the first part - try:

Sub Macro1()
Dim i As Integer

For i = 5 To 305
Range("G" & i).Select
ActiveCell.FormulaR1C1 = _
=VLOOKUP(RC[-1],STOCK!R2C1:R19562C10,HLOOKUP(R5C3,STOCK!R1C2:R2C10,2,FALSE),FALSE)"
Next i

End Sub



Regarding the second part:
I understand that you want to format cells in column F (green fill) if the value in column G is 1? Why won't you use Conditional Formatting?
Select the whole column F > Conditional Formatting > New Rule > Use a formula to determine which cells to format > enter:
=G1=1

I hope it helps.
 
Last edited:
Upvote 0
Because excel is funny about letting you copy colors from conditional formatting to another spreadsheet. I know a macro can be written to loop through everything without an actual formula but i'm having trouble writing it. so im just doing the best i can at the moment haha.
 
Upvote 0
Hey seth777, no problem & good luck! Let me know if you need a hand with further modifying your macro.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,541
Latest member
iparraguirre89

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