code help to add formula to empty row

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hi all

I would like some help with code that will look down column A and find first blank cell, once found place a simple formula through columns K:AC of that coresponding row. The formula would SUM all the cells above until blank row is found IN COLUMN I

I have this code that (I think) will find first blank row..

Code:
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    For Each rng In Range("A4:A" & LastRow)
        If rng = "" Then
but not sure if correct and/or how to complete the code to add the formula required

thanks in advance
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Once a blank row is found, lets say row 2517, that whole row is blank so I want a formula to SUM the cells above for each column K:AC (ie from row 2516 in this example so =SUM(K2516 upwards to the row containing blank cell in column I, so maybe =SUMKL2516:K2400 because cell I2400 is blank. This formula would then populate all cells in the row K:AC

Does that make sense?
 
Upvote 0
Try:

Code:
Sub Test()
    Dim LastRow As Long
    Dim FirstRow As Long
    With ActiveSheet
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        FirstRow = .Range("I" & LastRow).End(xlUp).Row
        .Range("K" & LastRow + 1 & ":AC" & LastRow + 1).Formula = "=SUM(K" & FirstRow & ":K" & LastRow & ")"
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

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