Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 304
Default New Loop, 2 workbooks

Hello all,
I have workbook A and workbook B. Both are the same, 130 sheets each. I need
to copy colum B from workbook B (which has changes) to A. I'm looking for a
loop that will start off on sheet 2 of both workbooks then go to the next
sheet (3) etc, to the end of both workbooks.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default New Loop, 2 workbooks

Sub Copy_Col_B()

Set Bk1 = Workbooks("A.xls")
Set Bk2 = Workbooks("B.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Next Sht


End Sub
"pgarcia" wrote:

Hello all,
I have workbook A and workbook B. Both are the same, 130 sheets each. I need
to copy colum B from workbook B (which has changes) to A. I'm looking for a
loop that will start off on sheet 2 of both workbooks then go to the next
sheet (3) etc, to the end of both workbooks.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 304
Default New Loop, 2 workbooks

Thanks, but it did not seem to work. And, I change it a bit, but sines it did
not work, it didn't. Here is what I'm trying to do. Question, I see where Bk1
changes to the next sheet, but when does Bk2 change to the next sheet?

Sub FuelCopy()

Set Bk1 = Workbooks("CMS Fuel Update20080801.xls")
Set Bk2 = Workbooks("CMS Fuel Update20080905.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Windows("CMS Fuel Update20080905.xls").Activate
Range("B1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone,
SkipBlanks:=False _
, Transpose:=False
Cells.Replace What:="[CMS Fuel Update20080801.xls]", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

Next Sht

End Sub

"Joel" wrote:

Sub Copy_Col_B()

Set Bk1 = Workbooks("A.xls")
Set Bk2 = Workbooks("B.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Next Sht


End Sub
"pgarcia" wrote:

Hello all,
I have workbook A and workbook B. Both are the same, 130 sheets each. I need
to copy colum B from workbook B (which has changes) to A. I'm looking for a
loop that will start off on sheet 2 of both workbooks then go to the next
sheet (3) etc, to the end of both workbooks.

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default New Loop, 2 workbooks

You don't need to activate and window when using the copy method like I did.
You also didn't reference the sht with your new REPLACE mwthod statement.
The code depends on the worksheets being in the same order in the two
workbooks. I'm referecing each worksheet by the index number 1 to 130 with
sheets(Sht). I added a method 2 below which I think is a little bit more
robust.


method 1

Sub FuelCopy()

Set Bk1 = Workbooks("CMS Fuel Update20080801.xls")
Set Bk2 = Workbooks("CMS Fuel Update20080905.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Bk2.sheets(Sht).Cells. _
Replace What:="[CMS Fuel Update20080801.xls]", _
Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False

Next Sht

End Sub

method 2

Sub FuelCopy()

Set Bk1 = Workbooks("CMS Fuel Update20080801.xls")
Set Bk2 = Workbooks("CMS Fuel Update20080905.xls")

For Sht = 2 To Bk1.Sheets.Count
ShtName = BK1.Sheets(Sht).Name
Bk1.Sheets(ShtName).Columns("B").Copy _
Bk2.Sheets(ShtName).Columns("B")
Bk2.sheets(ShtName).Cells. _
Replace What:="[CMS Fuel Update20080801.xls]", _
Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False

Next Sht

End Sub

"pgarcia" wrote:

Thanks, but it did not seem to work. And, I change it a bit, but sines it did
not work, it didn't. Here is what I'm trying to do. Question, I see where Bk1
changes to the next sheet, but when does Bk2 change to the next sheet?

Sub FuelCopy()

Set Bk1 = Workbooks("CMS Fuel Update20080801.xls")
Set Bk2 = Workbooks("CMS Fuel Update20080905.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Windows("CMS Fuel Update20080905.xls").Activate
Range("B1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone,
SkipBlanks:=False _
, Transpose:=False
Cells.Replace What:="[CMS Fuel Update20080801.xls]", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

Next Sht

End Sub

"Joel" wrote:

Sub Copy_Col_B()

Set Bk1 = Workbooks("A.xls")
Set Bk2 = Workbooks("B.xls")

For Sht = 2 To Bk1.Sheets.Count
Bk1.Sheets(Sht).Columns("B").Copy _
Bk2.Sheets(Sht).Columns("B")
Next Sht


End Sub
"pgarcia" wrote:

Hello all,
I have workbook A and workbook B. Both are the same, 130 sheets each. I need
to copy colum B from workbook B (which has changes) to A. I'm looking for a
loop that will start off on sheet 2 of both workbooks then go to the next
sheet (3) etc, to the end of both workbooks.

Thanks

Reply
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
New Loop, 2 workbooks pgarcia Excel Programming 2 September 5th 08 08:40 PM
Help:loop on two workbooks anan[_2_] Excel Programming 1 November 9th 05 11:18 PM
Loop with two workbooks Mike Excel Programming 2 January 14th 04 07:15 PM
loop through workbooks Keith Willshaw Excel Programming 2 September 19th 03 12:48 PM
loop through workbooks Ron de Bruin Excel Programming 1 September 18th 03 02:53 PM


All times are GMT +1. The time now is 04:59 PM.

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

About Us

"It's about Microsoft Excel"