+ Reply to Thread
Results 1 to 6 of 6

passing arguments and getting count in cells in vba

  1. #1
    Registered User
    Join Date
    12-26-2016
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    31

    passing arguments and getting count in cells in vba

    I have the below code where the count of a cell gets updated based on a search from a specific column, specific text and specific worksheet.

    How do I pass argument such that when it meets the condition, the count should be updated in the designated cell?

    Currently thecodes just goes to the worksheet mentioned and scans a column for a specific string and if it matches, it will give the total count of the matched row in the designated cell. So I need to apply the same code to 30+ cells to perform this task (with diff strings as the search conditions in diff sheets). If the above code can be converted into hash with arguments (arguments being the sheet name, text to search,range to place the count, col to search) and when the arguments (the string here) meets the condition, the count should be updated in the designated cell.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: passing arguments and getting count in cells in vba

    Quote Originally Posted by silverblade View Post
    So I need to apply the same code to 30+ cells to perform this task (with diff strings as the search conditions in diff sheets).
    It helps to give specifics. Where are the 30+ sheet names, search criteria, and output cells? Perhaps an example workbook would help.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    12-26-2016
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    31

    Re: passing arguments and getting count in cells in vba

    I have attached a excel.

    *The "Main" sheet is where the count is updated. THe strings are searched from other sheets in the workbook.

    * The cells where the count should be updated varies. I will just add the necessary cells.

    *The search criteria,keyword,sheet,range, etc is given in the sample code which I have posted.

    Exfrom code)

    In Cell, AE43, the count is updated only when the sheet "TT" meets the criteria mentioned.

    So, similarly I'll have to use the same kind of code 30+ times for different cells to get the data.

    Instead of this, If I could pass arguments (sheet name,cell range,searchtext,col name) and hash it, I can achieve this in a single subroutine or multiple subroutines.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: passing arguments and getting count in cells in vba

    Quote Originally Posted by silverblade View Post

    Instead of this, If I could pass arguments (sheet name,cell range,searchtext,col name) and hash it, I can achieve this in a single subroutine or multiple subroutines.
    Not sure what "hash it" means. I'm trying to understand what form the source arguments will take?

  5. #5
    Registered User
    Join Date
    12-26-2016
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    31

    Re: passing arguments and getting count in cells in vba

    I just saw somewhere that there is a "dictionary" function in vba that does the job of "hashing" .

    I'm trying to understand what form the source arguments will take? - Sheetname will always be the same sheet name from the file uploaded,search text will also be the same text..the same applies for other arguments also..

    I just told what I had in my mind. If you have a better idea to prevent repetitive code, please suggest.

  6. #6
    Registered User
    Join Date
    12-26-2016
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    31

    Re: passing arguments and getting count in cells in vba

    Any suggestions?

+ 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. Passing 2 arguments
    By PeterMac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2015, 05:34 AM
  2. Passing arguments in buttons
    By sprites in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2013, 11:47 AM
  3. Passing arguments?
    By RPhilbin83 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2011, 09:29 AM
  4. Passing Arguments
    By cosmarchy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2010, 04:36 PM
  5. Passing Arguments Between Spreadsheets
    By nt180792 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2009, 02:26 PM
  6. [SOLVED] Passing arguments from VBA to DLL
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-18-2006, 04:15 AM
  7. [SOLVED] Passing arguments to userforms
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 12:35 PM

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