LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Open four Wbooks, copy four columns from each to Master Wbook

Code seems to be okay until the first copy line which errors out in yellow.

Opens the four "state named" workbooks okay.

This line, one line up from error line shows lCol4 = 10 when cursor is hovered over it, which is correct.

Set rangeJ = Range("J1:J" & lCol4)

Is my syntax wrong with the copy lines?

Thanks.
Howard


Option Explicit

Sub MondayMornCopy()

'Idaho, Montana, Wyoming, Nebraska
Dim Idaho As Workbook, Montana As Workbook, Wyoming As Workbook, Nebraska As Workbook
Dim lCol1 As Long, lCol2 As Long, lCol3 As Long, lCol4 As Long
Dim rangeA As Range, rangeD As Range, rangeF As Range, rangeJ As Range
Dim copyArr As Variant
Dim i As Long

Workbooks.Open Filename:= _
"C:\Users\Howard Kittle\Documents\Idaho.xlsm"
Workbooks.Open Filename:= _
"C:\Users\Howard Kittle\Documents\Montana.xlsm"
Workbooks.Open Filename:= _
"C:\Users\Howard Kittle\Documents\Wyoming.xlsm"
Workbooks.Open Filename:= _
"C:\Users\Howard Kittle\Documents\Nebraska.xlsm"

lCol1 = Cells(Rows.Count, 1).End(xlUp).Row
lCol2 = Cells(Rows.Count, 4).End(xlUp).Row
lCol3 = Cells(Rows.Count, 6).End(xlUp).Row
lCol4 = Cells(Rows.Count, 10).End(xlUp).Row

Application.ScreenUpdating = False

copyArr = Array(Idaho, Montana, Wyoming, Nebraska)
For i = LBound(copyArr) To UBound(copyArr)

With copyArr(i)
Set rangeA = Range("A1:A" & lCol1)
Set rangeD = Range("D1:D" & lCol2)
Set rangeF = Range("F1:F" & lCol3)
Set rangeJ = Range("J1:J" & lCol4)

Workbooks("Master.xlsm").Sheets("Sheet1").Range("A " & Rows.Count).End(xlUp)(2) = copyArr(i).rangeA
Workbooks("Master.xlsm").Sheets("Sheet1").Range("D " & Rows.Count).End(xlUp)(2) = copyArr(i).rangeD
Workbooks("Master.xlsm").Sheets("Sheet1").Range("F " & Rows.Count).End(xlUp)(2) = copyArr(i).rangeF
Workbooks("Master.xlsm").Sheets("Sheet1").Range("J " & Rows.Count).End(xlUp)(2) = copyArr(i).rangeJ

copyArr(i).Save
copyArr(i).Close
End With

Next
Application.ScreenUpdating = True
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy some of selected columns to master sheet sanju[_2_] Excel Programming 3 April 17th 10 09:47 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook [email protected] Excel Programming 2 February 9th 07 10:28 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook [email protected] Excel Programming 0 February 9th 07 03:30 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook [email protected] Excel Programming 0 February 9th 07 03:30 PM
Open and copy all workbook sheets in a folder to a master file [email protected] Excel Discussion (Misc queries) 0 November 2nd 06 04:29 PM


All times are GMT +1. The time now is 12:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"