Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-03-2009, 10:34 AM
Cherub Cherub is offline
Registered User
 
Join Date: 05 Jun 2009
Location: New Mexico, USA
MS Office Version:Excel 2003
Posts: 21
Cherub is becoming part of the community
CountTriple ColumnsToTable Format

Please Register to Remove these Ads

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.

Code:
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
File Type: xls Book1.xls (78.5 KB, 6 views)

Last edited by Cherub; 07-06-2009 at 09:41 PM. Reason: SOLVED
Reply With Quote
  #2  
Old 07-03-2009, 10:40 AM
StephenR StephenR is offline
Forum Guru
 
Join Date: 26 Aug 2007
Location: London
Posts: 2,210
StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability
Re: CountTriple ColumnsToTable Format

If you want the last used row in column A it should be
Code:
LRA = Range("A" & Rows.Count).End(xlUp).Row
Reply With Quote
  #3  
Old 07-04-2009, 12:33 AM
Cherub Cherub is offline
Registered User
 
Join Date: 05 Jun 2009
Location: New Mexico, USA
MS Office Version:Excel 2003
Posts: 21
Cherub is becoming part of the community
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.
Reply With Quote
  #4  
Old 07-04-2009, 07:26 AM
StephenR StephenR is offline
Forum Guru
 
Join Date: 26 Aug 2007
Location: London
Posts: 2,210
StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability
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?
Reply With Quote
  #5  
Old 07-04-2009, 02:14 PM
Cherub Cherub is offline
Registered User
 
Join Date: 05 Jun 2009
Location: New Mexico, USA
MS Office Version:Excel 2003
Posts: 21
Cherub is becoming part of the community
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.
Reply With Quote
  #6  
Old 07-06-2009, 12:37 PM
Cherub Cherub is offline
Registered User
 
Join Date: 05 Jun 2009
Location: New Mexico, USA
MS Office Version:Excel 2003
Posts: 21
Cherub is becoming part of the community
Re: CountTriple ColumnsToTable Format

I am still having trouble with the original post. Any help, I greatly appreciate.
Reply With Quote
  #7  
Old 07-06-2009, 12:50 PM
DonkeyOte's Avatar
DonkeyOte DonkeyOte is offline
Forum Guru
 
Join Date: 22 Oct 2008
Location: Suffolk, UK
MS Office Version:2002 & 2007
Posts: 13,643
DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute
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 ?

Code:
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
Reply With Quote
  #8  
Old 07-06-2009, 09:41 PM
Cherub Cherub is offline
Registered User
 
Join Date: 05 Jun 2009
Location: New Mexico, USA
MS Office Version:Excel 2003
Posts: 21
Cherub is becoming part of the community
Re: CountTriple ColumnsToTable Format

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


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump