+ Reply to Thread
Results 1 to 7 of 7

Create continuous non blank table based on merge of separate dynamically filled tables

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Create continuous non blank table based on merge of separate dynamically filled tables

    Sure, sorry I realize my question is rather vague! I have created a sample workbook where Sheet1 contains the tables which are populated through a separate sheet/user forms, and Sheet2 has the table (could simply be a range) with the data populated as I need it to appear.

    Whenever the tables in Sheet1 get row data added/deleted, I want the master table in Sheet2 to be updated to contain all the data grouped without any spaces between the "City" table data.

    I have been trying some variations of array formulas that find the last empty cell/row in an array but that does not seem to address my issue so I wonder if the solution might be with VBA.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-23-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Create continuous non blank table based on merge of separate dynamically filled tables

    Update: I have found an array formula solution that is getting close to solving my problem! The formula is (entered using Ctrl+Shift+Enter):

    =IF(ROWS($2:2)<=COUNTA($B$2:$B$87),INDEX($B$2:$B$87,SMALL(IF($B$2:$B$87 <>"",ROW($B$2:$B$87)-MIN(ROW($B$2:$B$87))+1),ROWS($2:2))),"")

    Which returns the contents of the "City" columns in the tables on Sheet1 of my attached sample workbook, in order by skipping blank rows to the next row with a non-empty cell.
    This can be copied across for all the columns, however the issue is that it will also return the table header names!! I have tried inserting an OR condition in the IF statement such as: --IF(OR($B$2:$B$87 <>"",$B$2:$B$87 <>"City"),-- but this does not seem to work (neither does the AND condition).

    Any help would be greatly appreciated!

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Create continuous non blank table based on merge of separate dynamically filled tables

    escobf,

    Thanks for the workbook.

    With your raw data in worksheet Sheet1, the macro will create a new worksheet Results.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    
    Option Explicit
    Sub ReorgData()
    ' stanleydgromjr, 04/12/2013
    ' http://www.excelforum.com/excel-general/914529-create-continuous-non-blank-table-based-on-merge-of-separate-dynamically-filled-tables.html
    Dim w1 As Worksheet, wR As Worksheet
    Dim Area As Range, r As Long, sr As Long, er As Long, nr As Long, lr As Long
    Application.ScreenUpdating = False
    Set w1 = Worksheets("Sheet1")
    If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
    Set wR = Worksheets("Results")
    wR.UsedRange.Clear
    w1.Cells(1, 1).Resize(, 5).Copy wR.Cells(1, 1)
    wR.Cells(1, 5).Copy wR.Cells(1, 6).Resize(, 2)
    wR.Cells(1, 6).Resize(, 2).Value = [{"Calc1","Calc2"}]
    For Each Area In w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
      With Area
        sr = .Row
        er = sr + .Rows.Count - 1
        nr = wR.Range("B" & Rows.Count).End(xlUp).Offset(1).Row
        wR.Range("B" & nr).Resize(er - sr, 4).Value = w1.Range("B" & sr + 1 & ":E" & er).Value
      End With
    Next Area
    lr = wR.Cells(Rows.Count, 2).End(xlUp).Row
    With wR.Range("A2:A" & lr)
      .Formula = "=ROW()-1"
      .Value = .Value
    End With
    For r = 2 To lr Step 2
      With wR.Range("A" & r & ":G" & r).Interior
        .Pattern = xlSolid
        .PatternThemeColor = xlThemeColorAccent1
        .ThemeColor = xlThemeColorAccent1
        .TintAndShade = 0.799951170384838
        .PatternTintAndShade = 0.799981688894314
      End With
    Next r
    wR.Range("A2:G" & lr).Borders.Weight = xlThin
    wR.Columns("C:D").AutoFit
    wR.Activate
    Application.ScreenUpdating = True
    End Sub
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgData macro.
    Last edited by stanleydgromjr; 04-12-2013 at 09:01 PM.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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