PC Review


Reply
Thread Tools Rate Thread

Copy cell value from one worksheet to matching worksheet in another workbook

 
 
rech
Guest
Posts: n/a
 
      27th Sep 2011
I have 2 workbooks: OLD and NEW. They each have over 100 sheets
(most sheets are the same but some are different). I want to set the
value of cell C7 in the NEW workbook to the value from cell G40 in the
OLD workbook. I'd like open both workbooks then run a macro that runs
through every sheet in NEW and captures the sheet name then matches it
to the same sheet in the OLD workbook, copies the value from G40, then
pastes it into the NEW workbook C7.

Thanks so much for any help!!
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      27th Sep 2011
Option Explicit
Sub testme()

Dim OldWkbk As Workbook
Dim NewWkbk As Workbook
Dim oWS As Worksheet
Dim nWS As Worksheet

Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")

For Each oWS In OldWkbk.Worksheets
Set nWS = Nothing
On Error Resume Next
Set nWS = NewWkbk.Worksheets(oWS.Name)
On Error GoTo 0

If nWS Is Nothing Then
MsgBox oWS.Name & " doesn't exist in " & NewWkbk.Name
Else
nWS.Range("C7").Value = oWS.Range("g40").Value
End If

Next oWS

End Sub


Untested, but it did compile.



On 09/26/2011 19:39, rech wrote:
> I have 2 workbooks: OLD and NEW. They each have over 100 sheets
> (most sheets are the same but some are different). I want to set the
> value of cell C7 in the NEW workbook to the value from cell G40 in the
> OLD workbook. I'd like open both workbooks then run a macro that runs
> through every sheet in NEW and captures the sheet name then matches it
> to the same sheet in the OLD workbook, copies the value from G40, then
> pastes it into the NEW workbook C7.
>
> Thanks so much for any help!!


--
Dave Peterson
 
Reply With Quote
 
rech
Guest
Posts: n/a
 
      28th Sep 2011
On Sep 27, 6:21*am, Dave Peterson <peter...@XSPAMverizon.net> wrote:
> Option Explicit
> Sub testme()
>
> * * *Dim OldWkbk As Workbook
> * * *Dim NewWkbk As Workbook
> * * *Dim oWS As Worksheet
> * * *Dim nWS As Worksheet
>
> * * *Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
> * * *Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")
>
> * * *For Each oWS In OldWkbk.Worksheets
> * * * *Set nWS = Nothing
> * * * *On Error Resume Next
> * * * *Set nWS = NewWkbk.Worksheets(oWS.Name)
> * * * *On Error GoTo 0
>
> * * * *If nWS Is Nothing Then
> * * * * * MsgBox oWS.Name & " doesn't exist in " & NewWkbk.Name
> * * * *Else
> * * * * * nWS.Range("C7").Value = oWS.Range("g40").Value
> * * * *End If
>
> * * *Next oWS
>
> End Sub
>
> Untested, but it did compile.
>
> On 09/26/2011 19:39, rech wrote:
>
> > I have 2 workbooks: OLD and NEW. * They each have over 100 sheets
> > (most sheets are the same but some are different). *I want to set the
> > value of cell C7 in the NEW workbook to the value from cell G40 in the
> > OLD workbook. *I'd like open both workbooks then run a macro that runs
> > through every sheet in NEW and captures the sheet name then matches it
> > to the same sheet in the OLD workbook, copies the value from G40, then
> > pastes it into the NEW workbook C7.

>
> > Thanks so much for any help!!

>
> --
> Dave Peterson


Dave, You're my hero! This worked beautifully!! Is there any way to
exclude one or more sheets from this macro. In the OLD and NEW
workbooks, I have a Summary sheet and I do not want the macro to apply
to this sheet.
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      29th Sep 2011
One way:

Option Explicit
Sub testme()

Dim OldWkbk As Workbook
Dim NewWkbk As Workbook
Dim oWS As Worksheet
Dim nWS As Worksheet

Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")

For Each oWS In OldWkbk.Worksheets
Select Case UCase(oWS.Name)
Case Is = UCase("Summary"), _
UCase("anyother"), _
UCase("another")
'do nothing
Case Else
Set nWS = Nothing
On Error Resume Next
Set nWS = NewWkbk.Worksheets(oWS.Name)
On Error GoTo 0

If nWS Is Nothing Then
MsgBox oWS.Name & " doesn't exist in " & NewWkbk.Name
Else
nWS.Range("C7").Value = oWS.Range("g40").Value
End If
End Select

Next oWS

End Sub

(Still untested.)



On 09/28/2011 12:50, rech wrote:
> On Sep 27, 6:21 am, Dave Peterson<peter...@XSPAMverizon.net> wrote:
>> Option Explicit
>> Sub testme()
>>
>> Dim OldWkbk As Workbook
>> Dim NewWkbk As Workbook
>> Dim oWS As Worksheet
>> Dim nWS As Worksheet
>>
>> Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
>> Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")
>>
>> For Each oWS In OldWkbk.Worksheets
>> Set nWS = Nothing
>> On Error Resume Next
>> Set nWS = NewWkbk.Worksheets(oWS.Name)
>> On Error GoTo 0
>>
>> If nWS Is Nothing Then
>> MsgBox oWS.Name& " doesn't exist in "& NewWkbk.Name
>> Else
>> nWS.Range("C7").Value = oWS.Range("g40").Value
>> End If
>>
>> Next oWS
>>
>> End Sub
>>
>> Untested, but it did compile.
>>
>> On 09/26/2011 19:39, rech wrote:
>>
>>> I have 2 workbooks: OLD and NEW. They each have over 100 sheets
>>> (most sheets are the same but some are different). I want to set the
>>> value of cell C7 in the NEW workbook to the value from cell G40 in the
>>> OLD workbook. I'd like open both workbooks then run a macro that runs
>>> through every sheet in NEW and captures the sheet name then matches it
>>> to the same sheet in the OLD workbook, copies the value from G40, then
>>> pastes it into the NEW workbook C7.

>>
>>> Thanks so much for any help!!

>>
>> --
>> Dave Peterson

>
> Dave, You're my hero! This worked beautifully!! Is there any way to
> exclude one or more sheets from this macro. In the OLD and NEW
> workbooks, I have a Summary sheet and I do not want the macro to apply
> to this sheet.


--
Dave Peterson
 
Reply With Quote
 
rech
Guest
Posts: n/a
 
      29th Sep 2011
On Sep 29, 7:26*am, Dave Peterson <peter...@XSPAMverizon.net> wrote:
> One way:
>
> Option Explicit
> Sub testme()
>
> * * *Dim OldWkbk As Workbook
> * * *Dim NewWkbk As Workbook
> * * *Dim oWS As Worksheet
> * * *Dim nWS As Worksheet
>
> * * *Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
> * * *Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")
>
> * * *For Each oWS In OldWkbk.Worksheets
> * * * *Select Case UCase(oWS.Name)
> * * * * *Case Is = UCase("Summary"), _
> * * * * * * * * * *UCase("anyother"), _
> * * * * * * * * * *UCase("another")
> * * * * * *'do nothing
> * * * * *Case Else
> * * * * * *Set nWS = Nothing
> * * * * * *On Error Resume Next
> * * * * * *Set nWS = NewWkbk.Worksheets(oWS.Name)
> * * * * * *On Error GoTo 0
>
> * * * * * *If nWS Is Nothing Then
> * * * * * * * MsgBox oWS.Name & " doesn't exist in " & NewWkbk.Name
> * * * * * *Else
> * * * * * * * nWS.Range("C7").Value = oWS.Range("g40").Value
> * * * * * *End If
> * * * * *End Select
>
> * * *Next oWS
>
> End Sub
>
> (Still untested.)
>
> On 09/28/2011 12:50, rech wrote:
>
>
>
>
>
>
>
>
>
> > On Sep 27, 6:21 am, Dave Peterson<peter...@XSPAMverizon.net> *wrote:
> >> Option Explicit
> >> Sub testme()

>
> >> * * * Dim OldWkbk As Workbook
> >> * * * Dim NewWkbk As Workbook
> >> * * * Dim oWS As Worksheet
> >> * * * Dim nWS As Worksheet

>
> >> * * * Set OldWkbk = Workbooks("youroldworkbooknamehere.xls")
> >> * * * Set NewWkbk = Workbooks("yournewworkbooknamehere.xls")

>
> >> * * * For Each oWS In OldWkbk.Worksheets
> >> * * * * Set nWS = Nothing
> >> * * * * On Error Resume Next
> >> * * * * Set nWS = NewWkbk.Worksheets(oWS.Name)
> >> * * * * On Error GoTo 0

>
> >> * * * * If nWS Is Nothing Then
> >> * * * * * *MsgBox oWS.Name& *" doesn't exist in "& *NewWkbk.Name
> >> * * * * Else
> >> * * * * * *nWS.Range("C7").Value = oWS.Range("g40").Value
> >> * * * * End If

>
> >> * * * Next oWS

>
> >> End Sub

>
> >> Untested, but it did compile.

>
> >> On 09/26/2011 19:39, rech wrote:

>
> >>> I have 2 workbooks: OLD and NEW. * They each have over 100 sheets
> >>> (most sheets are the same but some are different). *I want to set the
> >>> value of cell C7 in the NEW workbook to the value from cell G40 in the
> >>> OLD workbook. *I'd like open both workbooks then run a macro that runs
> >>> through every sheet in NEW and captures the sheet name then matches it
> >>> to the same sheet in the OLD workbook, copies the value from G40, then
> >>> pastes it into the NEW workbook C7.

>
> >>> Thanks so much for any help!!

>
> >> --
> >> Dave Peterson

>
> > Dave, You're my hero! *This worked beautifully!! *Is there any way to
> > exclude one or more sheets from this macro. *In the OLD and NEW
> > workbooks, I have a Summary sheet and I do not want the macro to apply
> > to this sheet.

>
> --
> Dave Peterson


Wonderful!!! Worked perfectly! I appreciate this, Dave!!
 
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
Copy Rows From Worksheet Into Another Worksheet Same Workbook =?Utf-8?B?Sm9lIEsu?= Microsoft Excel Programming 6 7th Oct 2007 09:44 PM
Copy Values From Worksheet to another Worksheet same Workbook =?Utf-8?B?Sm9lIEsu?= Microsoft Excel Programming 1 6th Oct 2007 08:45 PM
How do I take a cell in one worksheet and add it into the formula in a different worksheet in the same workbook? Lexi Microsoft Excel Worksheet Functions 3 20th Sep 2006 05:52 PM
Copy from different workbook's worksheet into a single worksheet... johnprasun@gmail.com Microsoft Excel Misc 1 27th Oct 2005 07:27 PM
How can I link cell colours from worksheet to worksheet/workbook? =?Utf-8?B?RXZlbHlu?= Microsoft Excel Worksheet Functions 1 5th Jul 2005 09:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:17 AM.