Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel Macro Query

  • 15-08-2006 9:51am
    #1
    Closed Accounts Posts: 7,230 ✭✭✭


    It has been going on four years since I have done any VBA or excel macro coding so I said it might be best to ask this question here. I've tried googling but I didn't find any helpful information as of yet so I will continue googling while I await a response on here.

    Basically, I have a column in Excel where five different strings occur, "Paper", "PDF", "OOO - PAPER", and a couple of others. What I want to do is count how many occurances of each of these there is in the column. I'm fairly sure I just iterate through the column and have a couple of if statements which will increase a counter for each string... for instance:
    <while we are not at the end of the column>
    if column.text == "Paper" then
       papercounter=papercounter+1
    

    And so on. Is it possible that when this macro runs I can have it pop up with a message box with the results? I remember using MsgBox back in my VB days, can this be used inside an excel macro?

    If you could just point me in the right direction I'd really appreciate it.
    Cheers guys,
    sj.


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Yep, you can use MsgBox in an excel macro, no probs. Also have a look at COUNTIF in the excel helpfile.


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    Cheers EvilPhil, got it sorted with the following:

    [php]Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 15/08/2006 by localadmin
    '
    ' Keyboard Shortcut: Ctrl+h
    '

    Sheets("Sheet1").Select
    Worksheets("Sheet1").Range("A1:A200").Sort _
    Worksheets("Sheet1").Range("A1")

    'count the occurances

    Dim papercounter As Integer
    Dim pdfcounter As Integer
    Dim ooocounter As Integer
    Dim deliveryfailure As Integer

    For Each c In Worksheets("Sheet1").Range("A1:A200").Cells
    If c.Value = "PAPER" Then papercounter = papercounter + 1
    If c.Value = "PDF" Then pdfcounter = pdfcounter + 1
    If c.Value = "OOO - PAPER" Then ooocounter = ooocounter + 1
    If c.Value = "Delivery Failure" Then deliveryfailure = deliveryfailure + 1

    Next
    MsgBox ("Num of Paper " & papercounter)
    MsgBox ("Num of PDF " & pdfcounter)
    MsgBox ("Num of OOO PAPER " & ooocounter)
    MsgBox ("Num of Deivery Failure " & deliveryfailure)
    End Sub
    [/php]


Advertisement