PC Review


Reply
Thread Tools Rate Thread

how do I reference a cell in a previous sheet not by name, by orde

 
 
I.P.Phrielie
Guest
Posts: n/a
 
      3rd Feb 2008
I have an inventory of stock with formulae to calculate
"StartOfDay + Deliveries - Sales = EndOfDay"
I'm trying to write or record a macro to create a new worksheet and copy
EndOfDay from the previous days worksheet into the StartOfDay of the new
worksheet.
When I record the macro it records the actual name of the sheet ie
"Sheet4!E2" which does not give the incremental effect needed. Something like
"Sheets.Previous!E2" is needed

Cheers!
 
Reply With Quote
 
 
 
 
Mark Ivey
Guest
Posts: n/a
 
      3rd Feb 2008
Maybe you could use a named range for something like this...

Mark Ivey

"I.P.Phrielie" <(E-Mail Removed)> wrote in message
news:5942EE46-E8ED-40CE-9C51-(E-Mail Removed)...
> I have an inventory of stock with formulae to calculate
> "StartOfDay + Deliveries - Sales = EndOfDay"
> I'm trying to write or record a macro to create a new worksheet and copy
> EndOfDay from the previous days worksheet into the StartOfDay of the new
> worksheet.
> When I record the macro it records the actual name of the sheet ie
> "Sheet4!E2" which does not give the incremental effect needed. Something
> like
> "Sheets.Previous!E2" is needed
>
> Cheers!


 
Reply With Quote
 
I.P.Phrielie
Guest
Posts: n/a
 
      3rd Feb 2008
Never mind... I worked it out thanks...

"I.P.Phrielie" wrote:

> I have an inventory of stock with formulae to calculate
> "StartOfDay + Deliveries - Sales = EndOfDay"
> I'm trying to write or record a macro to create a new worksheet and copy
> EndOfDay from the previous days worksheet into the StartOfDay of the new
> worksheet.
> When I record the macro it records the actual name of the sheet ie
> "Sheet4!E2" which does not give the incremental effect needed. Something like
> "Sheets.Previous!E2" is needed
>
> Cheers!

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      3rd Feb 2008
Function PrevSheet(rg As Range)
n = Application.Caller.Parent.Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = Sheets(n - 1).Range(rg.Address).Value
End If
End Function

Sub newone()
Worksheets.Add
ActiveSheet.Range("A1").Formula = "=PrevSheet(E2)"
End Sub


Gord Dibben MS Excel MVP

On Sat, 2 Feb 2008 22:15:11 -0600, "Mark Ivey" <(E-Mail Removed)> wrote:

>Maybe you could use a named range for something like this...
>
>Mark Ivey
>
>"I.P.Phrielie" <(E-Mail Removed)> wrote in message
>news:5942EE46-E8ED-40CE-9C51-(E-Mail Removed)...
>> I have an inventory of stock with formulae to calculate
>> "StartOfDay + Deliveries - Sales = EndOfDay"
>> I'm trying to write or record a macro to create a new worksheet and copy
>> EndOfDay from the previous days worksheet into the StartOfDay of the new
>> worksheet.
>> When I record the macro it records the actual name of the sheet ie
>> "Sheet4!E2" which does not give the incremental effect needed. Something
>> like
>> "Sheets.Previous!E2" is needed
>>
>> Cheers!


 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      3rd Feb 2008
The worksheet object as a Previous property, e.g.

Set wks = ActiveSheet.Previous


--
Tim Zych
SF, CA

"I.P.Phrielie" <(E-Mail Removed)> wrote in message
news:5942EE46-E8ED-40CE-9C51-(E-Mail Removed)...
>I have an inventory of stock with formulae to calculate
> "StartOfDay + Deliveries - Sales = EndOfDay"
> I'm trying to write or record a macro to create a new worksheet and copy
> EndOfDay from the previous days worksheet into the StartOfDay of the new
> worksheet.
> When I record the macro it records the actual name of the sheet ie
> "Sheet4!E2" which does not give the incremental effect needed. Something
> like
> "Sheets.Previous!E2" is needed
>
> Cheers!



 
Reply With Quote
 
I.P.Phrielie
Guest
Posts: n/a
 
      3rd Feb 2008
Thanks everyone, but,

after 2 days of trying to find the answer in typically unhelpful "Help"
files I recorded the Macro using 'Crtl+PgUp' and 'Ctrl+PgDn' keys to navigate
between the sheets instead of the mouse... the resulting code for switching
between the sheets came out as "ActiveSheet.Previous.Select" and
"ActiveSheet.Next.Select"

I stumbled across the solution 2 minutes after posting... hahaha

Hope this helps someone else

"Tim Zych" wrote:

> The worksheet object as a Previous property, e.g.
>
> Set wks = ActiveSheet.Previous
>
>
> --
> Tim Zych
> SF, CA
>
> "I.P.Phrielie" <(E-Mail Removed)> wrote in message
> news:5942EE46-E8ED-40CE-9C51-(E-Mail Removed)...
> >I have an inventory of stock with formulae to calculate
> > "StartOfDay + Deliveries - Sales = EndOfDay"
> > I'm trying to write or record a macro to create a new worksheet and copy
> > EndOfDay from the previous days worksheet into the StartOfDay of the new
> > worksheet.
> > When I record the macro it records the actual name of the sheet ie
> > "Sheet4!E2" which does not give the incremental effect needed. Something
> > like
> > "Sheets.Previous!E2" is needed
> >
> > Cheers!

>
>
>

 
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
transfer contents from a cell in previous sheet if the sheet is a DarkNight Microsoft Excel New Users 1 9th Sep 2008 01:04 AM
Relative reference to a cell on a previous sheet feirhelen@gmail.com Microsoft Excel Misc 1 17th Jul 2006 07:27 PM
Reference Previous Sheet simonmarkjones@gmail.com Microsoft Excel Worksheet Functions 18 8th Oct 2005 08:34 AM
Reference to a cell in a previous sheet dolphinv4 Microsoft Excel Misc 5 13th May 2004 10:00 AM
help with previous sheet reference formula tj Microsoft Excel Misc 1 29th Apr 2004 12:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:22 PM.