VBA to add a formula until the last row is blank

L

Legacy 51064

Guest
I am having a little bit of trouble adding the following formulas to my vba code. I would like to enter these formulas into their respective columns until the bottom of column B. Data is entered into column B and the number of rows varries.


Column F
=IF(E2=0,0,LEFT(E2,FIND("–",E2,1)-2))

Column G
=Sum(H2:M2)

I appreciate any help that you offer.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Getting ready to go but will check back to see if nobody else picked you up.

BTW, you go to Cham~Bana?
 
Upvote 0
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> foo()
<SPAN style="color:#00007F">Dim</SPAN> Rng <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Set</SPAN> Rng = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Rng
    c.Offset(0, 4).FormulaR1C1 = "=if(RC[-1]=0,0,LEFT(RC[-1],FIND(" & """" & "-" & """" & ",RC[-1],1)-2))"
    c.Offset(0, 5).FormulaR1C1 = "=SUM(RC[1]:RC[6])"
<SPAN style="color:#00007F">Next</SPAN> c
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,206,946
Messages
6,075,792
Members
446,158
Latest member
octagonalowl

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