+ Reply to Thread
Results 1 to 8 of 8

Thread: CountTriple ColumnsToTable Format

  1. #1
    Registered User
    Join Date
    06-05-2009
    Location
    New Mexico, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    CountTriple ColumnsToTable Format

    I am using this macro to get Column A:C on Sheet1 to look like Column A:AA on Sheet2 of the attachment. I seem to be having trouble with the line of the code “LRA = Range("A:B" & Rows.Count).End(xlUp).Row”. JBeaucaire I hope I didn’t butcher your original too much. I am trying to do this with a macro instead of a pivot table. Any direction is much appreciated.

    Sub CountTripleColumnsToTableFormat()
    'Reassemble a three column list of repeating values into a table and count the duplicates
    Dim LC As Long, LRA As Long, LRC As Long
    Application.ScreenUpdating = False
    LRA = Range("A:B" & Rows.Count).End(xlUp).Row
    
    Range("C:C").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D1"), Unique:=True
    Range("D2:D11").Copy
    Range("D1").PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Range("D2:D11").ClearContents
    Application.CutCopyMode = False
    
    Cells.Columns.AutoFit
    Columns("D:D").Insert Shift:=xlToRight
    Range("A1:B" & LRA).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D2"), Unique:=True
    If Range("D2").Value = Range("D3").Value Then Range("D3").Delete (xlShiftUp)
    Range("Extract").Name.Delete
    
    LRC = Range("D" & Rows.Count).End(xlUp).Row
    LC = Cells(1, Columns.Count).End(xlToLeft).Column
    
    With Range("E2", Cells(LRC, LC))
    .FormulaR1C1 = "=SUMPRODUCT(--(R1C1:R" & LRA & "C1=RC3),--(R1C2:R" & LRA & "D2=R1C))"
    .Value = .Value
    .NumberFormat = "General"
    .HorizontalAlignment = xlCenter
    End With
    
    Columns("A:C").Delete Shift:=xlToLeft
    Range("C2").Select
    
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by Cherub; 07-06-2009 at 09:41 PM. Reason: SOLVED

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: CountTriple ColumnsToTable Format

    If you want the last used row in column A it should be
    LRA = Range("A" & Rows.Count).End(xlUp).Row

  3. #3
    Registered User
    Join Date
    06-05-2009
    Location
    New Mexico, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: CountTriple ColumnsToTable Format

    Hi Stephen. Thank you for the input. I changed that line of the code, but I am still not able to get this macro working. Any additional feedback is much appreciated.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: CountTriple ColumnsToTable Format

    Does a different line error now? If so, which one and what is the error? Or does the macro run but not do what you want?

  5. #5
    Registered User
    Join Date
    06-05-2009
    Location
    New Mexico, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: CountTriple ColumnsToTable Format

    Thank you for your question. The macro runs. I get a debug message. Once I close the debug message and click on the worksheet it seems like there is numbers all over the place. It is having problems.

  6. #6
    Registered User
    Join Date
    06-05-2009
    Location
    New Mexico, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: CountTriple ColumnsToTable Format

    I am still having trouble with the original post. Any help, I greatly appreciate.

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: CountTriple ColumnsToTable Format

    I've only looked at this briefly but based on your intended output sheet and source data perhaps the below might work for you ?

    Sub CountTripleColumnsToTableFormat()
    'Reassemble a three column list of repeating values into a table and count the duplicates
    Dim LC As Long, LRA As Long, LRC As Long
    Application.ScreenUpdating = False
    LRA = Cells(Rows.Count, "A").End(xlUp).Row
    Range("C:C").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D1"), Unique:=True
    With Range(Cells(2, "D"), Cells(Rows.Count, "D").End(xlUp))
        .Copy
        Range("D1").PasteSpecial Paste:=xlPasteAll, Transpose:=True
        .ClearContents
        Application.CutCopyMode = False
    End With
    Cells.Columns.AutoFit
    Columns("D:E").Insert Shift:=xlToRight
    Range("A1:B" & LRA).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D2"), Unique:=True
    If Range("D2").Value = Range("D3").Value Then Range("D3:E3").Delete (xlShiftUp)
    Range("Extract").Name.Delete
    LRC = Range("D" & Rows.Count).End(xlUp).Row
    LC = Cells(1, Columns.Count).End(xlToLeft).Column
    With Range("F2", Cells(LRC, LC))
        .FormulaR1C1 = "=SUMPRODUCT(--(R1C1:R" & LRA & "C1=RC4),--(R1C2:R" & LRA & "C2=RC5),--(R1C3:R" & LRA & "C3=R1C))"
        .Value = .Value
        .NumberFormat = "General;;"
        .HorizontalAlignment = xlCenter
    End With
    Columns("A:C").Delete Shift:=xlToLeft
    Range("C2").Select
    Application.ScreenUpdating = True
    End Sub

  8. #8
    Registered User
    Join Date
    06-05-2009
    Location
    New Mexico, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: CountTriple ColumnsToTable Format

    This is exactly what I was looking for help with. Thank you.

+ 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.2.0