Take last active Row

jay-excel

New Member
Joined
Aug 20, 2009
Messages
34
Hello,

I am wondering how I can configure the code below so that only the active rows (those with data in them) will be copied into the new workbook. Any suggestions?


Private Sub CommandButton1_Click()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Dim SourceRange As Range<o:p></o:p>
Dim DestRange As Range<o:p></o:p>
Dim DestWB As Workbook<o:p></o:p>
Dim DestSh As Worksheet<o:p></o:p>
Dim Lr As Long<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
With Application<o:p></o:p>
.ScreenUpdating = False<o:p></o:p>
.EnableEvents = False<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
If bIsBookOpen_RB("Inside Sales Stats 2009-2010 - master.xls") Then<o:p></o:p>
Set DestWB = Workbooks("Inside Sales Stats 2009-2010 - master.xls")<o:p></o:p>
Else<o:p></o:p>
Set DestWB = Workbooks.Open("\\central\BusSales\Public\Draft Work Orders\Testing Folder - Oxner\Sales Test\Inside Sales Stats 2009-2010 - master.xls")<o:p></o:p>
End If<o:p></o:p>
<o:p> </o:p>
<o:p></o:p>
Set SourceRange = ThisWorkbook.Sheets("Sheet1").Range("testrange")<o:p></o:p>
<o:p></o:p>
Set DestSh = DestWB.Worksheets("2009-December")<o:p></o:p>
<o:p> </o:p>
<o:p></o:p>
<o:p></o:p>
Lr = LastRow(DestSh)<o:p></o:p>
Set DestRange = DestSh.Range("A" & Lr + 1)<o:p></o:p>
<o:p> </o:p>
'We make DestRange the same size as SourceRange and use the Value<o:p></o:p>
'property to give DestRange the same values<o:p></o:p>
With SourceRange<o:p></o:p>
Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)<o:p></o:p>
End With<o:p></o:p>
DestRange.Value = SourceRange.Value<o:p></o:p>
<o:p> </o:p>
DestWB.Close savechanges:=True<o:p></o:p>
<o:p> </o:p>
With Application<o:p></o:p>
.ScreenUpdating = True<o:p></o:p>
.EnableEvents = True<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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