Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Macro to Copy certain values from different sheets to TIME Sheet

Hello All,
I am using Office 2003.
I have a workbook with 30+ Worksheets plus a Worksheet named TIME.

For Example:
Sheet - TIME has name ABC, DEF, GHI (not necessary in this order) in
Column C7 downwards
Other Sheets name ABC, DEF, GHI ... ... (these names are only for
explanatory purposes)

I wish to have a macro which when run should do the following on the
Sheet named TIME.

Look Up the Value in Column C of Sheet named TIME and Copy the value
of J:43 of respective sheets in Column G and the value of L:43 of
respective sheets in Column H. i.e value of J:43 of ABC Sheet should
be copied to TIME sheet against ABC in Column G and value of L:43 of
ABC Sheet should be copied to TIME sheet against ABC in Column H... and
for the rest of the sheets.

I hope I am clear

Any help would be greatly appreciated.

TIA

Rashid Khan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro to Copy certain values from different sheets to TIME Sheet

Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True

bReplace = False

With Worksheets("Time")
Set rng = Range("C7", Range("C7").End(xlDown))
End With

rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"

If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub

--
regards,
Tom Ogilvy

" wrote:

Hello All,
I am using Office 2003.
I have a workbook with 30+ Worksheets plus a Worksheet named TIME.

For Example:
Sheet - TIME has name ABC, DEF, GHI (not necessary in this order) in
Column C7 downwards
Other Sheets name ABC, DEF, GHI ... ... (these names are only for
explanatory purposes)

I wish to have a macro which when run should do the following on the
Sheet named TIME.

Look Up the Value in Column C of Sheet named TIME and Copy the value
of J:43 of respective sheets in Column G and the value of L:43 of
respective sheets in Column H. i.e value of J:43 of ABC Sheet should
be copied to TIME sheet against ABC in Column G and value of L:43 of
ABC Sheet should be copied to TIME sheet against ABC in Column H... and
for the rest of the sheets.

I hope I am clear

Any help would be greatly appreciated.

TIA

Rashid Khan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Macro to Copy certain values from different sheets to TIME Sheet

Thanks Tom,
You are a saviour. Works fine! But there is one small hitch.
There is a blank row which is C12. So the macro works fine from Row 7
to Row 11.

I modified the following line to overcome the Blank row and go right
down (Pardon my knowledge of VBA...I hope there is a better way)

Set rng = Range("C7", Range("C7").End(xlDown).End(xlDown).End(xlDown))

However, the above gives #REF! in Column G and H for the Blank Row
i.e. Row 12.

Can you fix this problem?

Thanks
Rashid Khan


On Jul 7, 6:08 pm, Tom Ogilvy
wrote:
Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True

bReplace = False

With Worksheets("Time")
Set rng = Range("C7", Range("C7").End(xlDown))
End With

rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"

If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub

--
regards,
Tom Ogilvy



" wrote:
Hello All,
I am using Office 2003.
I have a workbook with 30+ Worksheets plus a Worksheet named TIME.


For Example:
Sheet - TIME has name ABC, DEF, GHI (not necessary in this order) in
Column C7 downwards
Other Sheets name ABC, DEF, GHI ... ... (these names are only for
explanatory purposes)


I wish to have a macro which when run should do the following on the
Sheet named TIME.


Look Up the Value in Column C of Sheet named TIME and Copy the value
of J:43 of respective sheets in Column G and the value of L:43 of
respective sheets in Column H. i.e value of J:43 of ABC Sheet should
be copied to TIME sheet against ABC in Column G and value of L:43 of
ABC Sheet should be copied to TIME sheet against ABC in Column H... and
for the rest of the sheets.


I hope I am clear


Any help would be greatly appreciated.


TIA


Rashid Khan- Hide quoted text -


- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro to Copy certain values from different sheets to TIME She

First, I inadvertently omitted the periods inside the With statement in the
previous code (so it you use that, add them), so I have added them and
changed the sense of the statement to come up from the bottom. This should
overcome any blank cells being an impediment to processing the sheet names.

This assumes you want to included all the populated cells below row 6.

Second, I added a line to remove any formulas in cells returning an Error.

Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True

bReplace = False

With Worksheets("Time")
Set rng = .Range("C7",.Cells(rows.count,"C").End(xlup))
End With

rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"
On Error Resume Next
rng.offset(0,4).Resize(,1).SpecialCells( _
xlFormulas,xlErrors).ClearContents
On Error goto 0
If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub

This code is untested so you might have to tweak it if there are any typos.

--
Regards,
Tom Ogilvy


" wrote:

Thanks Tom,
You are a saviour. Works fine! But there is one small hitch.
There is a blank row which is C12. So the macro works fine from Row 7
to Row 11.

I modified the following line to overcome the Blank row and go right
down (Pardon my knowledge of VBA...I hope there is a better way)

Set rng = Range("C7", Range("C7").End(xlDown).End(xlDown).End(xlDown))

However, the above gives #REF! in Column G and H for the Blank Row
i.e. Row 12.

Can you fix this problem?

Thanks
Rashid Khan


On Jul 7, 6:08 pm, Tom Ogilvy
wrote:
Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True

bReplace = False

With Worksheets("Time")
Set rng = Range("C7", Range("C7").End(xlDown))
End With

rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"

If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub

--
regards,
Tom Ogilvy



" wrote:
Hello All,
I am using Office 2003.
I have a workbook with 30+ Worksheets plus a Worksheet named TIME.


For Example:
Sheet - TIME has name ABC, DEF, GHI (not necessary in this order) in
Column C7 downwards
Other Sheets name ABC, DEF, GHI ... ... (these names are only for
explanatory purposes)


I wish to have a macro which when run should do the following on the
Sheet named TIME.


Look Up the Value in Column C of Sheet named TIME and Copy the value
of J:43 of respective sheets in Column G and the value of L:43 of
respective sheets in Column H. i.e value of J:43 of ABC Sheet should
be copied to TIME sheet against ABC in Column G and value of L:43 of
ABC Sheet should be copied to TIME sheet against ABC in Column H... and
for the rest of the sheets.


I hope I am clear


Any help would be greatly appreciated.


TIA


Rashid Khan- Hide quoted text -


- Show quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Macro to Copy certain values from different sheets to TIME She

Hi Tom,
Thanks a million!
I just added the following to catch another error :

rng.Offset(0, 5).Resize(, 1).SpecialCells( _
xlFormulas, xlErrors).ClearContents

It works fine. Thanks once again.

Rashid Khan

On Jul 7, 7:48 pm, Tom Ogilvy
wrote:
First, I inadvertently omitted the periods inside the With statement in the
previous code (so it you use that, add them), so I have added them and
changed the sense of the statement to come up from the bottom. This should
overcome any blank cells being an impediment to processing the sheet names.

This assumes you want to included all the populated cells below row 6.

Second, I added a line to remove any formulas in cells returning an Error.

Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True

bReplace = False

With Worksheets("Time")
Set rng = .Range("C7",.Cells(rows.count,"C").End(xlup))
End With

rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"
On Error Resume Next
rng.offset(0,4).Resize(,1).SpecialCells( _
xlFormulas,xlErrors).ClearContents
On Error goto 0
If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub

This code is untested so you might have to tweak it if there are any typos.

--
Regards,
Tom Ogilvy



" wrote:
Thanks Tom,
You are a saviour. Works fine! But there is one small hitch.
There is a blank row which is C12. So the macro works fine from Row 7
to Row 11.


I modified the following line to overcome the Blank row and go right
down (Pardon my knowledge of VBA...I hope there is a better way)


Set rng = Range("C7", Range("C7").End(xlDown).End(xlDown).End(xlDown))


However, the above gives #REF! in Column G and H for the Blank Row
i.e. Row 12.


Can you fix this problem?


Thanks
Rashid Khan


On Jul 7, 6:08 pm, Tom Ogilvy
wrote:
Sub EFG()
Dim rng As Range, bReplace As Boolean
' this puts in formulas. If you want them
' replaced with the values they return, then
' set the value of bReplace to True


bReplace = False


With Worksheets("Time")
Set rng = Range("C7", Range("C7").End(xlDown))
End With


rng.Offset(0, 4).Formula = "=INDIRECT(""'""&C7&""'!J43"")"
rng.Offset(0, 5).Formula = "=INDIRECT(""'""&C7&""'!L43"")"


If bReplace Then
With rng.Offset(0, 4).Resize(, 2)
.Formula = .Value
End With
End If
End Sub


--
regards,
Tom Ogilvy


" wrote:
Hello All,
I am using Office 2003.
I have a workbook with 30+ Worksheets plus a Worksheet named TIME.


For Example:
Sheet - TIME has name ABC, DEF, GHI (not necessary in this order) in
Column C7 downwards
Other Sheets name ABC, DEF, GHI ... ... (these names are only for
explanatory purposes)


I wish to have a macro which when run should do the following on the
Sheet named TIME.


Look Up the Value in Column C of Sheet named TIME and Copy the value
of J:43 of respective sheets in Column G and the value of L:43 of
respective sheets in Column H. i.e value of J:43 of ABC Sheet should
be copied to TIME sheet against ABC in Column G and value of L:43 of
ABC Sheet should be copied to TIME sheet against ABC in Column H... and
for the rest of the sheets.


I hope I am clear


Any help would be greatly appreciated.


TIA


Rashid Khan- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



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
Copy the same column from 50 sheets into a new sheet macro help! [email protected][_2_] Excel Programming 7 July 12th 06 01:57 PM
Macro to copy Column 1 of all sheets to a seperate sheet. Rajula Excel Programming 1 June 12th 06 05:34 PM
Copy Macro values to new sheet Crowbar via OfficeKB.com New Users to Excel 0 December 20th 05 10:10 PM
in VBA Sheets("mysheet").Copy Befo=Sheets(1) how do i get a reference to the newly created copy of this sheet? Daniel Excel Worksheet Functions 1 July 6th 05 09:57 PM
VBA to copy sheets (as values) that begin with the same sheet name Brent Walker Excel Programming 5 April 28th 05 05:38 PM


All times are GMT +1. The time now is 01:31 PM.

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"