Macro: Merge Sheets with variable row count

shane_aldrich

Board Regular
Joined
Oct 23, 2009
Messages
148
Hi all needing help with a macro...

I'm merging data from a sheet2 to the top of sheet1, so I need a macro that will count the number of non-blank rows in column e of sheet2...

Once the count is determined, starting at row 1, highlight that number of rows, and cut them and insert them above row1 on sheet1,

Any help would be much appreciated
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Figured it out if anyone could use.

Sub d()
'Formulas Filldown A_AH
Dim Column_A_AH As Long
Column_A_AH = Range("E1:E" & Range("E1").End(xlDown).Row).Rows.Count
Range("A1" & ":AH" & Column_A_AH).Select
Selection.Cut
Sheets("Sheet1").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
End Sub
 
Upvote 0
Maybe not the best VBA code but it should work:

Sub Macro1()
Dim lLastRow As Long
Sheets("Sheet2").Select
On Error GoTo ErrorHandler
With ActiveSheet
lLastRow = .Cells.Find _
(What:="*", After:=.Range("A1"), SearchDirection:=xlPrevious).Row
End With
ActiveSheet.Select
Range("A" & lLastRow).Select

ErrorHandler:
If Err.Number <> 0 Then
Range("A3").Select
End If

Result = ActiveCell.Row
Rows("1:" & Result).Select
Selection.Cut
Sheets("Sheet1").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
rootytrip

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