+ Reply to Thread
Results 1 to 3 of 3

Having trouble creating a button that counts when two strings are side-by-side

Hybrid View

  1. #1
    Registered User
    Join Date
    07-29-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    16

    Having trouble creating a button that counts when two strings are side-by-side

    Hi everyone,

    I am completely new to Excel VBA so I am really hoping I can get some help *thank you in advance*.

    I have an excel worksheet that has different string values in the cells and I have to specifically count when the values "NSW" are found beside each other (i.e. NSW, NSW) in the excel sheet. I have only created a function so far (not sure if it is right...) but I I really need to do is create a command button that would show the results of the count in a message box, but I am stuck. Any help would be greatly appreciated!

    Here is what I have so far:

    Function CountIfAll(Crit1, Crit2, Rng As Range) As Long
    Dim rCell As Range
        
        CountIfAll = 0
        
        For Each rCell In Rng
            If rCell = Crit1 And rCell.Offset(, 1) = Crit2 Then
                CountIfAll = CountIfAll + 1
            End If
        Next rCell
    End Function
    Last edited by alansidman; 08-18-2014 at 04:10 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Having trouble creating a button that counts when two strings are side-by-side

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-29-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    16

    Re: Having trouble creating a button that counts when two strings are side-by-side

    Thank you Alan, I will read through the forum rules.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Set Excel 2010 as default program when installed side-by-side with 2013
    By AlvaroSiza in forum Excel General
    Replies: 1
    Last Post: 08-31-2013, 06:45 PM
  2. VBA to copy data from multiple sheets side-by-side into one sheet matching date
    By MHCapcog in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-02-2013, 06:11 PM
  3. Replies: 0
    Last Post: 04-19-2009, 10:53 PM
  4. Creating stacked graphs side-by-side
    By yssem in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-14-2006, 07:18 AM
  5. Replies: 1
    Last Post: 03-20-2006, 10:15 PM

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