Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed coding a macro to adjust the source of information each time it is run


I am a serious newby with macros, but would like to modify what I am
doing to avoid having to edit a series of macros I use, everytime I use
them. Essentially, I have a bunch of different workbooks that are more
or less templated copies of each other but vary according to certain
details that don't affect the macro. I have recorded a simple macro
that starts in a cell on the active sheet and then needs to refer to
the next sheet in the book to run a simply formula and pull the
information back to the active sheet. My problem is that everytime I
update the workbook I need to copy the active sheet and apply a new
name to the newly copied sheet. Names of sheets are simply the date
corresponding to the information on that sheet (ie. 03 10 30). My macro
keeps referring back to the sheet I used when I originally recorded it
(obviously!). I would like to edit the code so that the macro knows to
simly go the sheet immediately behind the active sheet. This is a
sample of my code:

Sub start_ct()
'
' start_ct Macro
' Macro recorded 10/13/2003 by Family
'

'
Range("G38:M46").Select
Selection.ClearContents
Range("F38").Select
ActiveCell.FormulaR1C1 = _
"='03 09 17'!RC-'03 09 17'!RC[2]-'03 09 17'!RC[3]+'03 09
17'!RC[4]+'03 09 17'!RC[7]"
Selection.Copy
Range("F39:F46").Select
ActiveSheet.Paste
End Sub


ANy ideas?

Thanks, Lori!


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Help needed coding a macro to adjust the source of information each time it is run

We'll create a variable to hold th e"source" sheet's
name...

DIM sSheet as String

suppose the sheet you want is yesterday's date...

sSheet = format$(Date-1,"yy mm dd")

' make some adjustment for weekends holidays
' or simply read the date from the active sheet...say its
in cell A1...

sSheet = Format$(Range("A1").Value,"yy mm dd")

Now we can use this in our formula...

Sub start_ct()
Dim sSheet As String
sSheet = Format$(Range("A1").Value, "'yy mm dd'")
With Range("G38:M46")
.ClearContents
.FormulaR1C1 = "=" & _
sSheet & "!RC-" & sSheet & "!RC[2]-" & _
sSheet & "!RC[3]+" & sSheet & "!RC[4]+" & _
sSheet & "!RC[7]"
End With
End Sub


Note that I've also tidied the code a bit - works fine on
my test book ...

HTH
Patrick Molloy
Microsoft Excel MVP

PS for my workbook, email me directly

-----Original Message-----

I am a serious newby with macros, but would like to

modify what I am
doing to avoid having to edit a series of macros I use,

everytime I use
them. Essentially, I have a bunch of different

workbooks that are more
or less templated copies of each other but vary

according to certain
details that don't affect the macro. I have recorded a

simple macro
that starts in a cell on the active sheet and then needs

to refer to
the next sheet in the book to run a simply formula and

pull the
information back to the active sheet. My problem is that

everytime I
update the workbook I need to copy the active sheet and

apply a new
name to the newly copied sheet. Names of sheets are

simply the date
corresponding to the information on that sheet (ie. 03

10 30). My macro
keeps referring back to the sheet I used when I

originally recorded it
(obviously!). I would like to edit the code so that the

macro knows to
simly go the sheet immediately behind the active sheet.

This is a
sample of my code:

Sub start_ct()
'
' start_ct Macro
' Macro recorded 10/13/2003 by Family
'

'
Range("G38:M46").Select
Selection.ClearContents
Range("F38").Select
ActiveCell.FormulaR1C1 = _
"='03 09 17'!RC-'03 09 17'!RC[2]-'03 09 17'!RC[3]+'03 09
17'!RC[4]+'03 09 17'!RC[7]"
Selection.Copy
Range("F39:F46").Select
ActiveSheet.Paste
End Sub


ANy ideas?

Thanks, Lori!


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

.

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
Please help on coding the macro. Eric Excel Worksheet Functions 0 March 11th 08 03:11 PM
HELP - coding on Macro! Eric Excel Worksheet Functions 3 February 21st 08 12:26 AM
coding macro Boss Excel Discussion (Misc queries) 0 November 13th 07 12:17 PM
VBA coding needed badly Seeking help New Users to Excel 9 July 7th 06 06:58 AM
Macro Coding JulieB[_2_] Excel Programming 1 October 3rd 03 09:08 PM


All times are GMT +1. The time now is 06:57 AM.

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"