Solved

Button Separating out like numbers from columns

Posted on 2012-03-26
4
267 Views
Last Modified: 2012-03-28
I am looking to see how I can capture the numbers of 5, 4, 3, 2, and 1's in columns AJ thru AO.  However, columns (AJ & AK) needs to be combined and column (AL & AM), and (AN & AO) respectively.  Right now I have to do a pivot table to capture this information. My process is to copy and paste for example column AK under AJ prior to doing the pivot table and then AL and AM and so on.  Is there a macro that can be written with a button that can automatically capture this information upon request? Please note that because I am copying column AK (site B) underneath column AJ (site A) the pivot table picks up the name for site A and so on.  Attached are the spreadsheet and an example of desired outcome?
IWARspreadsheet-database-FEB12.xls
Sample-pivot-table-output.xls
0
Comment
Question by:Melbut
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
kgerb earned 500 total points
Comment Utility
Hello Melbut,
Try this.  Run the sub Summarize and it will populate the Output sheet.  I think it will do what you want.  Give it a shot and let me know.

Kyle
Sub Summarize()
Dim lFRow As Long, lLRow As Long, sCols(), sAdd As String
Dim i As Long, j As Long
lFRow = 4
ReDim sCols(1 To 3, 1 To 2)
sCols(1, 1) = "AJ"
sCols(1, 2) = "AK"
sCols(2, 1) = "AL"
sCols(2, 2) = "AM"
sCols(3, 1) = "AN"
sCols(3, 2) = "AO"
For i = 1 To 3
    lLRow = Columns(sCols(i, 1) & ":" & sCols(i, 2)).Find("*", SearchDirection:=xlPrevious).Row
    sAdd = sCols(i, 1) & 1 & ":" & sCols(i, 2) & lLRow
    For j = 0 To 5
        Range("rngTot" & i).Offset(j + 1) = CountValues(Range(sAdd), j)
    Next j
Next i
    
End Sub

Function CountValues(rng As Range, lVal As Long) As Long
Dim c As Range, sAdd As String
CountValues = 0
With rng
    Set c = .Find(lVal, LookIn:=xlValues, lookat:=xlWhole)
    If Not c Is Nothing Then
        sAdd = c.Address
        Do
            CountValues = CountValues + 1
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> sAdd
    End If
End With
End Function

Open in new window

Q-27649277-RevA.xlsm
0
 

Author Comment

by:Melbut
Comment Utility
This looks to be functioning  with no problems.  Thank you!
0
 

Author Closing Comment

by:Melbut
Comment Utility
Thank you for the quick response!
0
 
LVL 12

Expert Comment

by:kgerb
Comment Utility
You're welcome.  Glad to help.
Kyle
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
My experience with Windows 10 over a one year period and suggestions for smooth operation
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now