Macro to insert Blank row and add data

mystic42

New Member
Joined
Jan 10, 2014
Messages
17
Hi

I am very new to writing VBA's and am stupped on getting this macro right, I need to do the following:

- When the value in a cell in column C changes compared to the cell value above - a blank line needs to be inserted between the different values

- then I need to copy the values from the cells below the Blank Row Columns A B C J L into the blank cell as well

and add on the blank line "Balance" in Column D

Any help would be greatly appreciated.

Thanks

Andrea
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Clarification : I am currently using Excel 2003 but am upgrading to 2010 at the end of the month:

ABCD E F G H I JK L
Header RowHeader Row1 Header Row
C2ApplesC22X123BoxApplesBalance 5,000.0020.12.13
C3ApplesC3Apples3X123BoxApplesPURCHASE…. 5,000.0020.12.13
C4ApplesC4Apples4X124BoxApplesSALE….- 2,000.0021.12.13
bC5ApplesC5Apples5X125BoxApplesPURCHASE…. 400.0021.12.13
eC6ApplesaC6ApplesR6X126BoxApplesPURCHASE…. 4.0004.01.14
fC7OrangesfC7Applese7X127BoxApplesSALE….- 500.0005.01.14
oC8OrangestC8s8z22CartOrangesBalance 550.0013.12.13
rC9PearseC9Orangesu9z22CartOrangesPURCHASE…. 550.0013.12.13
eC10PearsrC10Orangesl10y35BoxOrangesSALE….- 500.0020.12.13
C11PearsC11t11 etc..
C12PearsC12Pears
C13Pears
C14Pears
C15Pears

<tbody>
</tbody>

Hope this explains better what I am trying to do:

Thanks for any help that can be provided.

Regards

Andrea
 
Upvote 0
Hi

I am very new to writing VBA's and am stupped on getting this macro right, I need to do the following:

- When the value in a cell in column C changes compared to the cell value above - a blank line needs to be inserted between the different values

- then I need to copy the values from the cells below the Blank Row Columns A B C J L into the blank cell as well

and add on the blank line "Balance" in Column D

Any help would be greatly appreciated.

Thanks

Andrea
Hi Andrea,

Maybe try the following VBA code. It should do literally what you ask for in the above quote, but if it's really what you want ... who knows?. Your posts 2 and 3 don't clarify much at all for me.
Code:
Sub insert_blank_rows_etcr()

Dim r As Long, c As Long, a, u(), i As Long, k As Long
r = Cells.Find("*", , , , xlByRows, xlPrevious).Row
c = Cells.Find("*", , , , xlByColumns, xlPrevious).Column
ReDim u(1 To r, 1 To 1)
a = Cells(3).Resize(r + 1)
Cells(c + 1) = 1: Cells(c + 1).Resize(r).DataSeries

For i = 1 To r
    If a(i, 1) <> a(i + 1, 1) Then k = k + 1: u(k, 1) = i
Next i

Cells(r + 1, c + 1).Resize(k) = u
Cells(1).Resize(r + k, c + 1).Sort Cells(c + 1), Header:=xlNo
Cells(c + 1).Resize(r + k).ClearContents

For i = 1 To k
    Cells(u(i, 1) + i, 1).Resize(, 3) = Cells(u(i, 1) + i + 1, 1).Resize(, 3).Value
    If i < k Then Cells(u(i, 1) + i, 4) = "Balance"
    Cells(u(i, 1) + i, 10) = Cells(u(i, 1) + i + 1, 10)
    Cells(u(i, 1) + i, 12) = Cells(u(i, 1) + i + 1, 12)
Next i

End Sub
 
Upvote 0
Hello mirabeau

I get a runtime error 1004 and when I select debug the following line in highlighted:

a = Cells(3).Resize(r + 1)


Andrea
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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