Formula problem when inserting new rows...

Tonibee

New Member
Joined
Jan 15, 2019
Messages
2
Hi all, first post. I'm an occasional excel user... Usually I can figure things out but this seemingly innocuous problem has me stumped and I can't track down a solution.

I've written an accounting spreadsheet for myself. Column F is for adding bank transactions and column J tracks the bank balance by taking the entry from the previous row (e.g. J13) and adding the entry from column F of the current row (e.g. F14). The formula is =sum(J13+F14).

The formula copies fine in the usual way (using the drag handle). However, when I add a new row using the macro button, the cell reference for the J column freezes and doesn't advance, giving the formula =sum(J13+F15). I've tried two different macro codes to insert new rows and both have the same result. I've copied my macro below, but I think I'm missing something much more basic... Any ideas?

Thank you.

Code:
Private Sub CommandButton1_Click()Dim rw As Long, cl As Long, lastRw As Long
   
               lastRw = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).Row
               ActiveSheet.Cells(lastRw, 1).Select
               Selection.EntireRow.Insert
               n = ActiveCell.Row - 1
               For cl = 1 To Columns.Count
                If Cells(n - 1, cl).HasFormula Then
                    Cells(n - 1, cl).Copy Cells(n + 1, cl)
                End If
               Next
                Cells(n, 1).Select
               
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
FYI

You dont need a SUM() around that formula.

=sum(J13+F14)

is the same as

=J13+F14
 
Upvote 0
Thank you, SpecialK-99

Although your answer isn't a solution, it's good enough to spark that annoying bit of realisation that makes one feel like a right numpty!! And it also gives me a bit of advice, so thanks! :)

Basically, I've populated the whole column at the outset with the formula by dragging the top cell to the bottom, and that is the problem! New rows are inserted between the lines with the existing formula and that's what messes it up. Deleting the formula from unused rows has fixed the problem!

Cheers!

FYI

You dont need a SUM() around that formula.

=sum(J13+F14)

is the same as

=J13+F14
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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