Count number of Row Insert Rows Paste Data Macro

beantownmt

New Member
Joined
Aug 29, 2011
Messages
11
Hi all.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Any help that could be offer would be great.<o:p></o:p>
I have a master file which has all my formulas in it.<o:p></o:p>
My Macro is able to import the data I need into a temp data sheet in the master file.<o:p></o:p>
I'm stuck on a couple of issues 1. Need to count the number of rows that are need to be inserted into the Master Sheet.(data report never has the same number of rows) 2. Copy and Paste the data (into the correct columns) 3. Maintain the current formulas and continue to update the line numbers.<o:p></o:p>
Hope I wasn't to confusing in my explanation. <o:p></o:p>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
1) To count the number of rows in your temp data sheet, assuming even row1 has data:
Code:
Dim NewRows as Long

With Sheets("Temp Data Sheet")
    NewRows = .Range("A" & .Rows.Count).End(xlUp).Row
End With

For now, let's assume there is a Sum formula of some kind at the bottom of column A and across that whole row, so the new data needs to be inserted just above that.

3) Maintain the formulas and formatting from the last row of data.
Code:
Dim InsertRow As Long

With Sheets("Master")
    InsertRow = .Range("A" & .Rows.Count).End(xlup).Row
    .Rows(InsertRow - 1).Copy
    .Rows(InsertRow).Resize(NewRows).Insert xlShiftDown
    .Rows(InsertRow).Resize(NewRows).SpecialCells(xlconstants).Clearcontents
End With

2) Lastly you move the data into the new columns, you'll have to tweak this, of course, since only you know the correct "target" columns, but assuming each of the columns of data on the temp sheet has a matching target column:
Code:
With Sheets("Temp Data Sheet")
    Sheets("Master").Range("C" & InsertRow).Resize(NewRows).Value = .Range("A1:A" & NewRows).Value
    Sheets("Master").Range("E" & InsertRow).Resize(NewRows).Value = .Range("B1:B" & NewRows).Value
    Sheets("Master").Range("H" & InsertRow).Resize(NewRows).Value = .Range("C1:C" & NewRows).Value
    'etc...
End With
 
Last edited:
Upvote 0
Change this:
Code:
InsertRow = .Range("A" & .Rows.Count).End(xlup).Row


...to this:
Code:
InsertRow = 16

...or 15, or 17...
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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