Results 1 to 9 of 9

Dynamic Ranges from Different Sheets Question

Threaded View

nicoan Dynamic Ranges from Different... 02-23-2014, 06:55 PM
TMS Re: Dynamic Ranges from... 02-23-2014, 08:38 PM
nicoan Re: Dynamic Ranges from... 02-23-2014, 09:18 PM
TMS Re: Dynamic Ranges from... 02-23-2014, 09:30 PM
nicoan Re: Dynamic Ranges from... 02-24-2014, 12:02 AM
TMS Re: Dynamic Ranges from... 02-24-2014, 05:55 AM
TMS Re: Dynamic Ranges from... 02-24-2014, 07:39 AM
TMS Re: Dynamic Ranges from... 02-24-2014, 01:02 PM
nicoan Re: Dynamic Ranges from... 02-24-2014, 02:03 PM
  1. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,069

    Re: Dynamic Ranges from Different Sheets Question

    OK, this is the code to add the Tables and Formulae:

    ' Module: mAddTables
    
    ' dynamic_ranges_and_sheets_question TMS v3.xlsm
    ' author:    TMShucks Excel Aid
    
    ' title:    Dynamic Ranges from Different Sheets Question
    ' thread:   http://www.excelforum.com/excel-general/991616-dynamic-ranges-from-different-sheets-question.html
    ' from:     nicoan
    
    Option Private Module
    Option Explicit
    
    Sub sAddTables()
    Dim sh As Worksheet
    Dim lLR As Long
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        .EnableEvents = False
    End With
    
    On Error GoTo lblFormula
    
    ' convert ranges to Tables on Symbol sheets
    ' loop through each sheet in the workbook sheets collection
    For Each sh In ThisWorkbook.Worksheets
        ' applies to everything except Control sheet
        If sh.Name <> "Control" Then
            With sh
                ' determine last row of data on the sheet
                lLR = .Range("A" & .Rows.Count).End(xlUp).Row
                ' insert a Table
                ' and name it based on the worksheet name (Symbol)
                .ListObjects.Add( _
                    xlSrcRange, _
                    .Range("$A$1:$F$" & lLR), , _
                    xlYes) _
                        .Name = "tab" & sh.Name
            End With
        End If
    Next 'sh
    
    lblFormula:
    On Error GoTo 0
    On Error GoTo lblExit
    
    ' add formulas to Control sheet
    With Sheets("Control")
        ' having named the Tables using the sheet (Symbol) name
        ' we can use INDIRECT to reference the Symbol
        .Range("Tabla1[All Time Max Price]").FormulaR1C1 = _
            "=MAX(INDIRECT(""tab"" & Tabla1[[#This Row],[Symbol]]  & ""[Close]""))"
        .Range("Tabla1[1Y Max Price]").FormulaR1C1 = _
            "=MAX(INDEX(INDIRECT(""tab"" &  Tabla1[[#This Row],[Symbol]] & ""[Close]"")," & Chr(10) & "              MATCH(MAX(INDIRECT(""tab""& Tabla1[[#This Row],[Symbol]]& ""[Date]"")),INDIRECT(""tab"" & Tabla1[[#This Row],[Symbol]] & ""[Date]""),0)-251):" & Chr(10) & "              INDEX(INDIRECT(""tab"" &  Tabla1[[#This Row],[Symbol]] & ""[Close]"")," & Chr(10) & "              MATCH(MAX(INDIRECT(""tab"" & Tabla1[[#This Row],[Symbol]] & ""[Date]"")),INDIRECT(""tab"" & Tabla1[[#This Row],[Symbol]] & ""[Date]""),0)))"
        ' just add some formatting to the data for consistency
        .Range("Tabla1[[All Time Max Price]:[1Y Max Price]]").NumberFormat = "0.00"
    End With
    
    lblExit:
    On Error GoTo 0
    
    With Application
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    
    End Sub

    Please see the attached updated workbook to try it. I don't know how it will perform with 400 sheets ...

    Regards, TMS
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Main sheet populated by multiple sheets, dynamic ranges
    By cmack in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2014, 09:14 AM
  2. [SOLVED] Dynamic Ranges - Create Using VBA as looping through Sheets
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2013, 11:00 AM
  3. [SOLVED] a question regarding dynamic ranges and charts
    By Wazooli in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-28-2005, 07:06 PM
  4. dynamic Ranges
    By adehilis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2005, 12:06 PM
  5. Dynamic Formulas with Dynamic Ranges
    By Ralph Howarth in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-21-2005, 05:06 AM

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