+ Reply to Thread
Results 1 to 3 of 3

Create new tab + paste columns based on multiple criteria

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2011 mac
    Posts
    3

    Create new tab + paste columns based on multiple criteria

    Hi all,

    I am new to VBA and am trying to automate a task.
    Here is a sample of my workbook: testdata.xls

    Here's what I'm looking to do:
    • create a new tab for each unique entry in a column (each tab will be named after the entry) - DONE
    • insert a date column in column A that would be easily changeable (e.g. being able to start on Jan 1st, being able to go from a date to another)
    • for each combination (date, id), I would like to copy the values of columns D and E from Sheet1 and paste them in the row that matches the date in the newly created tab

    Notes: the initial list in Sheet1 might miss some dates, which means it is important that the new tabs have a list of dates that is generated separately and is complete


    The end result would be something like:
    In terms of tabs: Sheet1, name1, name2, name3
    With in each tab: rows (01/01/12, 02/01/12, 03/01/12,...), columns (id, data1, data2) and the matching content for each combination (date,id) from Sheet1


    Any help or guidance would be greatly appreciated. I am also happy to post my final work once it's working so anyone can reuse it!

    Thanks a lot
    Matias

  2. #2
    Registered User
    Join Date
    07-03-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2011 mac
    Posts
    3

    Re: Create new tab + paste columns based on multiple criteria

    I understand this type of question has been asked in the past but I could not figure out how to switch the macros I found to respond to a dynamic condition combination.

    What I am trying to do is after the new tabs are created is: for tab name=x, copy paste content of each (id,date) combination from i to the end of the worksheet, where id=x.

    Hope this helps...

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2011 mac
    Posts
    3

    Re: Create new tab + paste columns based on multiple criteria

    Here is the code I am using to create a new tab for each unique entry of column C:


    Sub Add_tab_for_unique_values()

    Dim Lastrow As Long, rngUniques As Range, cell As Range, ws As Worksheet

    Set ws = ActiveSheet
    Application.ScreenUpdating = False

    Lastrow = ws.Range("C" & Rows.Count).End(xlUp).Row
    ws.Range("C1:C" & Lastrow).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Set rngUniques = ws.Range("C2:C" & Lastrow).SpecialCells(xlCellTypeVisible)
    ws.ShowAllData

    On Error Resume Next
    For Each cell In rngUniques
    If cell.Value <> "" Then
    If Len(Sheets(cell.Value).Name) = 0 Then
    Sheets.Add(After:=Sheets(Sheets.Count)).Name = cell.Value
    End If
    End If
    Next cell
    On Error GoTo 0

    ws.Activate
    Application.ScreenUpdating = True

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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