PC Review


Reply
Thread Tools Rate Thread

Copy second row and Last row to new worksheet

 
 
Carlee
Guest
Posts: n/a
 
      11th Jul 2008
Hello All. I use the following code to copy the first row, and last
populated row to a new work book. It works great.

Question: How can I modify this code so that it takes the SECOND row, not
the first, and last populated row.

Your help is always appreciated.

***************CODE**********************************

Sub ExportRaglanDailySubmission()
'these have to do with THIS workbook
'name of the sheet to get data from
Const sourceSheet = "Site Reading Log"
'column that always have value in it in last row
Const sourceKeyColumn = "A"
'****
'This is the name you want to give to the
'NEW workbook created each time to put new data
'into as set up this code will overwrite any
'existing file of this name without any warning.
Const newWorkbookName = "Raglan Daily Reading.xls"
'******

Dim sourceBook As String
Dim destBook As String
Dim sourceRange As Range
Dim destRange As Range
Dim MaxLastRow As Long
Dim pathToUserDesktop As String

'we are in pre-Excel 2007 version
MaxLastRow = Rows.Count

'keeps screen from flickering
'speeds things up also
Application.ScreenUpdating = False
sourceBook = ThisWorkbook.Name
Workbooks.Add ' create new book
destBook = ActiveWorkbook.Name
Windows(sourceBook).Activate
Worksheets(sourceSheet).Select

Set sourceRange = ActiveSheet.Rows("1:1")
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("1:1")

destRange.Value = sourceRange.Value
Range(sourceKeyColumn & MaxLastRow).End(xlUp).Select

Set sourceRange = ActiveSheet.Rows(ActiveCell.Row & ":" & ActiveCell.Row)
Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("2:2")
destRange.Value = sourceRange.Value
Set destRange = Nothing
Set sourceRange = Nothing

Application.DisplayAlerts = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

--
Carlee
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      11th Jul 2008
Change this line

Set sourceRange = ActiveSheet.Rows("1:1")

to

Set sourceRange = ActiveSheet.Rows("2:2")

However your code is not detecting the first used row it is taking row 1 but
if that is OK the above change should work.

--

Regards,
Nigel
(E-Mail Removed)



"Carlee" <(E-Mail Removed)> wrote in message
news:65011ED5-D5A8-48F5-8510-(E-Mail Removed)...
> Hello All. I use the following code to copy the first row, and last
> populated row to a new work book. It works great.
>
> Question: How can I modify this code so that it takes the SECOND row, not
> the first, and last populated row.
>
> Your help is always appreciated.
>
> ***************CODE**********************************
>
> Sub ExportRaglanDailySubmission()
> 'these have to do with THIS workbook
> 'name of the sheet to get data from
> Const sourceSheet = "Site Reading Log"
> 'column that always have value in it in last row
> Const sourceKeyColumn = "A"
> '****
> 'This is the name you want to give to the
> 'NEW workbook created each time to put new data
> 'into as set up this code will overwrite any
> 'existing file of this name without any warning.
> Const newWorkbookName = "Raglan Daily Reading.xls"
> '******
>
> Dim sourceBook As String
> Dim destBook As String
> Dim sourceRange As Range
> Dim destRange As Range
> Dim MaxLastRow As Long
> Dim pathToUserDesktop As String
>
> 'we are in pre-Excel 2007 version
> MaxLastRow = Rows.Count
>
> 'keeps screen from flickering
> 'speeds things up also
> Application.ScreenUpdating = False
> sourceBook = ThisWorkbook.Name
> Workbooks.Add ' create new book
> destBook = ActiveWorkbook.Name
> Windows(sourceBook).Activate
> Worksheets(sourceSheet).Select
>
> Set sourceRange = ActiveSheet.Rows("1:1")
> Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("1:1")
>
> destRange.Value = sourceRange.Value
> Range(sourceKeyColumn & MaxLastRow).End(xlUp).Select
>
> Set sourceRange = ActiveSheet.Rows(ActiveCell.Row & ":" &
> ActiveCell.Row)
> Set destRange = Workbooks(destBook).Worksheets("Sheet1").Rows("2:2")
> destRange.Value = sourceRange.Value
> Set destRange = Nothing
> Set sourceRange = Nothing
>
> Application.DisplayAlerts = False
> Application.DisplayAlerts = True
> Application.ScreenUpdating = True
>
> End Sub
>
> --
> Carlee


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending copy worksheet to mailrecipient - mail adress indicated incell in worksheet Snoopy Microsoft Excel Discussion 1 19th Aug 2009 12:51 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 4 7th Sep 2006 05:05 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 0 7th Sep 2006 03:37 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 2 22nd Sep 2004 03:30 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:48 PM.