+ Reply to Thread
Results 1 to 10 of 10

How to CountA for Column Where Header = Something

Hybrid View

alfykunable How to CountA for Column... 01-30-2012, 07:20 AM
tom1977 Re: How to CountA for Column... 01-30-2012, 07:35 AM
alfykunable Re: How to CountA for Column... 01-30-2012, 07:44 AM
tom1977 Re: How to CountA for Column... 01-31-2012, 03:31 AM
tom1977 Re: How to CountA for Column... 01-31-2012, 04:40 AM
alfykunable Re: How to CountA for Column... 01-31-2012, 05:02 AM
tom1977 Re: How to CountA for Column... 01-31-2012, 08:14 AM
alfykunable Re: How to CountA for Column... 01-31-2012, 01:41 PM
tom1977 Re: How to CountA for Column... 02-01-2012, 05:41 AM
alfykunable Re: How to CountA for Column... 02-01-2012, 05:48 AM
  1. #1
    Registered User
    Join Date
    12-13-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    47

    How to CountA for Column Where Header = Something

    Hey Guys,

    I've been trying to make a macro that sota summarizes the counts of certain Columns that have certain names.

    NO no based on position on the cells but Column Header Name.

    Sub Summarize()
    
    Dim a As Long
    a = Application.WorksheetFunction.CountA(Cells(2, 1).Resize(9, 1))
    MsgBox Cells(1, 1) & Chr(10) & a
    
    End Sub

    This code works on the first column but I want it to be Column Header Specific..

    likeso: counta for column where column_name="SKUs"

    Thanks

    Alfred
    Attached Files Attached Files
    Last edited by alfykunable; 02-01-2012 at 05:49 AM.

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to CountA for Column Where Header = Something

    hi
    try this
    Sub Summarize()
    
    Dim a As Long, b As Long
    Dim h As String
    
    h = InputBox("choose header")
    b = Application.WorksheetFunction.Match(h, Rows(1), 0)
    
    a = Application.WorksheetFunction.CountA(Cells(2, b).Resize(9, 1))
    MsgBox Cells(1, b) & Chr(10) & a
    
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    12-13-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: How to CountA for Column Where Header = Something

    Hi Tom,


    THANKS!! works perfectly for one column.

    I have just like that 4-8 columns whose count I would need, how to make it work for an array?

    SKus, Descriptions, Header3, Header4 etc?


    Thanks SOOOOO MUCH!!!

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to CountA for Column Where Header = Something

    I am not sure that this is what You want but try on your example this code
    Sub Summarize()
    
    Dim a As Long, b As Long
    Dim h As Integer
    
    For b = 1 To 4
    a = Application.WorksheetFunction.CountA(Cells(2, b).Resize(9, 1))
    MsgBox Cells(1, b) & Chr(10) & a
    Next
    
    End Sub

  5. #5
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to CountA for Column Where Header = Something

    next try
    Sub Summarize()
    Dim a As Long, b As Long
    Dim c As Range
    Dim last As Long
    last = Cells(1, Columns.Count).End(xlToLeft).Column
    For Each c In Range(Cells(1, 1), Cells(1, last))
    If c.Value Like "SKUs" Or c.Value Like "Description" Or c.Value Like "header1" Or c.Value Like "header2" Then
    b = c.Column
    a = Application.WorksheetFunction.CountA(Cells(2, b).Resize(9, 1))
    MsgBox Cells(1, b) & Chr(10) & a
    End If
    Next
    End Sub

  6. #6
    Registered User
    Join Date
    12-13-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: How to CountA for Column Where Header = Something

    Thats What I was looking for

    but is there any way to show all that in one popup? instead of 5?

  7. #7
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to CountA for Column Where Header = Something

    Sub Summarize()
    Dim a As Long, b As Long
    Dim c As Range
    Dim last As Long
    Dim x As String
    last = Cells(1, Columns.Count).End(xlToLeft).Column
    
    For Each c In Range(Cells(1, 1), Cells(1, last))
    If c.Value Like "SKUs" Or c.Value Like "Description" Or c.Value Like "header1" Or c.Value Like "header2" Then
    b = c.Column
    a = Application.WorksheetFunction.CountA(Cells(2, b).Resize(9, 1))
    x = x & Chr(10) & Cells(1, b) & Chr(10) & a
    End If
    Next
    MsgBox x
    End Sub

  8. #8
    Registered User
    Join Date
    12-13-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: How to CountA for Column Where Header = Something

    Perfection

    THANKS A TON TOM!!!!!

  9. #9
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to CountA for Column Where Header = Something

    last row in column 1 you can find this way:
    rlast = Cells(Rows.Count, 1).End(xlUp).Row

  10. #10
    Registered User
    Join Date
    12-13-2011
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: How to CountA for Column Where Header = Something

    I wish i could reward you with more reputation!!!!!

    THANKS MATE!

+ 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