Macro to add rows from wbk1 to end of wbk2 (1 Viewer)

dcavaiani

Registered User.
Local time
Today, 14:56
Joined
May 26, 2014
Messages
385
Found this sample code but I don't know exactly how to designate the "file" name ??

Error below is "subscript is out of range"

Sub CopySheetToOtherWbk()
Dim CopyFromWbk As Workbook
Dim CopyToWbk As Workbook
Dim ShToCopy As Worksheet

Set CopyFromWbk = Workbooks("virginweeklysummary.xls")
Set ShToCopy = CopyFromWbk.Worksheets("Sheet1")
--- ERROR --- Set CopyToWbk = Workbooks("c:\bobs excel only\hoursbilled.xls")

ShToCopy.Copy After:=CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
End Sub
 

Trevor G

Registered User.
Local time
Today, 20:56
Joined
Oct 1, 2009
Messages
2,341
The code you have found is copying a sheet not a row, if you can supply a little more information then you get a better response.

Questions:


  1. Which sheet is the data to be copied from
  2. Which row is to be copied
  3. Which workbook is to be opened and its file path to be included
  4. Which sheet is the row to be pasted to
  5. Any extra information please add here.
 

dcavaiani

Registered User.
Local time
Today, 14:56
Joined
May 26, 2014
Messages
385
The code you have found is copying a sheet not a row, if you can supply a little more information then you get a better response.

Questions:


  1. Which sheet is the data to be copied from (virginweeklysummary.xls - ALL OF SHEET1 (although there are some "blank/incomplete" rows contained in that sheet which I would like skipped over too)
  2. Which row is to be copied - (THE ENTIRE SHEET1)
  3. Which workbook is to be opened and its file path to be included (the copy FROM wbk is c:\bobs excel only\virginweeklysummary.xls) which I have open and am coding the macro inside of this wbk)
  4. Which sheet is the row to be pasted to (C:\Bob excel only\hoursbilled.xls and the sheet name is also hoursbilled)
  5. Any extra information please add here.

(I was also wondering if the column heads have to be is the EXACT same sequence left to right in each wbk - The column HEADINGS are the same but fields are flip flopped)
 

Trevor G

Registered User.
Local time
Today, 20:56
Joined
Oct 1, 2009
Messages
2,341
To make it easier for the code to follow correctly it would be better to have the Column Headings to be laid out the same.
 

dcavaiani

Registered User.
Local time
Today, 14:56
Joined
May 26, 2014
Messages
385
To explain further, the virginweeklysummary.xls / sheet2 is the data entry - of weekly time card data. The sheet1 of that workbook is an auto summary layout of the time card IN/OUT times/data entered into the sheet2. Once all input is clean/edited nd totals balanced, then the sheet1 can be "auto" (via the VBA macro) added to the BOTTOM of the hoursbilled.xls - which is a history file of all the time card weekly summaries.
 

Users who are viewing this thread

Top Bottom