Problem with inserting row in macro

asmales

New Member
Joined
Jul 2, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am re-posting this as two good members informed me that an attachment had not been received correctlt

I am not an expert at excel macros and I am at a loss as to how to go forward.
I have attached the part of the spreadsheet and the macro written so far. When I have entered data into rows I3 to M3 I have no problem.
When I Pressthe macro to enter the data into the information set below it enters it into Row 20 I3 to M3, which a want. If I repeat this again a number of times it will keep adding the rows and eventually enter over the TOTAL row in row 22.
I want to be able to move the row with the TOTAL (row 20) down after each transaction to prevent this from happening.
As I enter a number of rows I want the total (which shows in row I22 to auto sum the number of rows that have been entered.

I have tried numerous ways but it is beyond me.


Sub SalesTransaction()

Worksheets("GENERAL SALES").Unprotect "AMBIT1ON"

Set wsSALES = Worksheets("GENERAL SALES")

With wsSALES

Set rng = .Range("I3:I29").Find(.Range("I3").Value, , , xlWhole).Offset(8, 0)

tmprow = rng.End(xlDown).Row

If tmprow = Rows.Count Then

tmprow = .Range("I" & Rows.Count).End(xlUp).Row + 1

ElseIf .Range("I" & tmprow).Value = "CODE" Then

tmprow = .Range("I" & tmprow).End(xlUp).Row + 1

ElseIf rng.Value <> "" Then

tmprow = rng.End(xlDown).Row + 1

End If

.Range("I" & tmprow & ":J" & tmprow & ":K" & tmprow & ":L" & tmprow & ":M" & tmprow) = Range("I3:M3").Value

End With

Range("I3").ClearContents
Range("J3").ClearContents

Range("L3").ClearContents

End Sub

Since this the first time that I have used this post thread forgive me if I make a mess of this



1688394418276.png
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
VBA Code:
Dim lr&
        lr = Range("N19").SpecialCells(xlCellTypeLastCell).Row
        Range("M" & lr + 1).Value = "TOTAL"
        Range("N" & lr + 1).FormulaLocal = "=SUM(N20:N" & lr & ")"
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,246
Members
449,093
Latest member
Vincent Khandagale

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