Finding empty cells in a column of a subtotaled range and pasting in a formula

Nikeyg

New Member
Joined
Jan 22, 2018
Messages
15
Hello everyone

I'm currently working with a range of data that I need to subtotal, but after subtotaling I need to input formulas on the subtotal lines to reference the data in the subtotaled line one row above (the data filtered out).

I'm currently using this for column A, but obviously this is running it constantly all the way down the worsksheet
Code:
    Dim ws As Worksheet    Set ws = ActiveSheet
    For Each cell In ws.Columns(1).Cells
        If IsEmpty(cell) = True Then cell.Select
        
    ActiveCell.FormulaR1C1 = "=+R[-1]C"
    Next cell

Once done I need to repeat these steps for columns G, H, I, J, N and O.

Thanks in advance for the help.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Slight update
I've found this to work with the formula I want to paste in, and I'm just repeating this code for each column I want it to happen to
Code:
Set wks = ActiveSheetWith wks
    Range("A1").Select
   col = ActiveCell.Column
   'or
   'col = .range("A1,G1,H1,I1,J1,N1,O1,V1").column


   Set rng = .UsedRange  'try to reset the lastcell
   LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
   Set rng = Nothing
   On Error Resume Next
   Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
                  .Cells.SpecialCells(xlCellTypeBlanks)
   On Error GoTo 0
   If rng Is Nothing Then
       MsgBox "No blanks found"
       Exit Sub
   Else
       rng.FormulaR1C1 = "=+R[-1]C"
   End If

The only issue is that this brings the data down to the last used row, which includes the Grand total line of the Subtotal.
Any idea how I can get it to not use that row?
 
Upvote 0
Try

Code:
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row - 1

Or

Code:
LastRow = .Range("[COLOR=#ff0000]B[/COLOR]" & Rows.Count).End(xlUp).Row - 1  'Change "B" to the column with the total
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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