+ Reply to Thread
Results 1 to 5 of 5

Using Sheet Names or a varibale in Formulae

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    6

    Smile Using Sheet Names or a varibale in Formulae

    Hi

    I have a macro that in a loop creates a sheet, called rngName, then calculates a value on this sheet (amongst other things).
    This value has to then be copied to another sheet, call it Numbers.

    The loop then loops to the next sheet it creates (rngName+1), etc.

    I can copy the value so ---
    Numbers.Range("B2").value=rngName.Range("Q10").value

    but if the value on rngName sheet is changed, I would like this reflected in the Numbers sheet, as it would if you manually entered the cell reference '=rngName!Q10' into the cell Numbers!B2 in Excel for example.
    I thought I could do this by using a formula---

    Numbers.Range("B2").formula= "=rngName!Q10"

    but I don't know how to format using a variable sheet name in a function.

    Any other suggestions as to how to, what is essentially just referencing one cell to another, not the value or the formula, would be very appreciated.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Using Sheet Names or a varibale in Formulae

    Create a working formula, though how to do that best would be easier to determine if you posted your code.

    If Numbers and rngName are worksheet objects, then change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    If rngName is an index number (depends on your other code)
    Please Login or Register  to view this content.
    though if you post your code we can be certain what to do.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-22-2014
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Using Sheet Names or a varibale in Formulae

    Here's my code, with non-relevant stuff removed.

    PHP Code: 
    Sub New_series_sheets()

    ' Creates new sheets for each series
     
    Dim rngName As Range, rngFill As Range
    Dim i As Integer

    Set rngName = Sheets("Series total").Range("a2")
    Set rngFill = Sheets("RSQ").Range("b2")

    '   
    Create copy of series total sheet

        Sheets
    ("Series total").Select
        Sheets
    ("Series total").copy After:=Sheets(Sheets.Count)
        
    Sheets(Sheets.Count).Name "temp"
       
       
    Do Until rngName.Value ""
           
           
    Sheets.Count
           Sheets
    .Add After:=Sheets(Sheets.Count)

         
    Sheets(1).Name rngName.Value
        
    '   Populate with data copied from series total copy

        Worksheets("temp").Range("B2:M2").copy
        Worksheets(i + 1).Range("$B$2:$M$2").PasteSpecial xlPasteValues
        
           
    '   
    Remove copied row

        Sheets
    ("temp").Range("2:2").EntireRow.Delete
        Set rngName 
    rngName.Offset(1)
       
        
    '   MAPE

        Worksheets(i + 1).Range("Q12").Formula = "=100*(SUM(ABS(B$6-B$14),ABS(C$6-C$14),ABS(D$6-D$14),ABS(E$6-E$14),ABS(F$6-F$14),ABS(G$6-G$14),ABS(H$6-H$14),ABS(I$6-I$14),ABS(J$6-J$14),ABS(K$6-K$14),ABS(L$6-L$14),ABS(M$6-M$14)))/(SUM(B$6:M$6))"
        
        
    '   
    Copy MAPE values to RSQ sheet

        rngFill
    .Offset(02).Value Worksheets(1).Range("Q11").Value
        rngFill
    .Offset(05).Value Worksheets(1).Range("Q12").Value
        
            
        Set rngFill 
    rngFill.Offset(10)


       
    Loop
       

    '   Removes temp sheet

    Application.DisplayAlerts = False
    Worksheets("temp").Delete
    Application.DisplayAlerts = True
     
        
    End Sub 
    rngName is taken from a column on another sheet and used to name each new sheet, working down the column. rngFill is the cell that the MAPE value needs to be copied to on another sheet called RSQ. I need this cell to update if I should adjust the numbers on any of the rngName sheets. At the moment it just copies the values across.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Using Sheet Names or a varibale in Formulae

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-22-2014
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Using Sheet Names or a varibale in Formulae

    Worked like a charm. Many thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] .find problem passing a varibale
    By wanncody in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2013, 02:56 PM
  2. Sumproduct in varibale text array
    By Ada01 in forum Excel General
    Replies: 2
    Last Post: 03-22-2012, 05:13 PM
  3. Replies: 1
    Last Post: 04-04-2010, 04:15 AM
  4. Formulae using range names
    By Wendy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-23-2005, 10:06 AM
  5. Help in this code for range with varibale
    By psk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2005, 10:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1