+ Reply to Thread
Results 1 to 6 of 6

error trying to use vba countifs function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    error trying to use vba countifs function

    I have two workbooks

    i have this code which gives me an error

    Junk1 = Application.WorksheetFunction.CountIfs( _
    study_number_range, Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2"), _
    Received_col_range, "<>" & "", _
    Closed_col_range, ">=" & start_date1, _
    Closed_col_range, "<=" & end_date1)
    any idea why it does not work?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error trying to use vba countifs function

    Are all those things declared variables?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: error trying to use vba countifs function

    they are ranges........see code below


    Set Received_col_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(Received_Col) & "2:" & alphacol(Received_Col) & (last_row1 + 1))
                                                                        
    Set study_number_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(1) & "1:" & alphacol(1) & (last_row1 + 1))
                                                                        
    Set Closed_col_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(Closed_Col) & "2:" & alphacol(Closed_Col) & (last_row1 + 1))
                                                                        
    'Set study_1_range = Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2")
    
                                                                        
    'Total closed
    Junk1 = Application.WorksheetFunction.CountIfs( _
    study_number_range, "=" & Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2").Value, _
    Received_col_range, "<>" & "", _
    Closed_col_range, ">=" & start_date1, _
    Closed_col_range, "<=" & end_date1)

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: error trying to use vba countifs function

    ok...not sure why but i changed the set ranges all the same starting point.....some were 1 and some were 2..........changed all starting points of the ranges to "1" and it works......i think........

    Set Received_col_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(Received_Col) & "1:" & alphacol(Received_Col) & (last_row1 + 1))
                                                                        
    Set study_number_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(1) & "1:" & alphacol(1) & (last_row1 + 1))
                                                                        
    Set Closed_col_range = Workbooks(wrkbookname1).Worksheets(wkrsheetname1). _
                Range(alphacol(Closed_Col) & "1:" & alphacol(Closed_Col) & (last_row1 + 1))
                                                                        
    'Set study_1_range = Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2")
    'Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2").Value
                                                                        
    'Total closed
    Junk1 = Application.WorksheetFunction.CountIfs( _
    study_number_range, "=" & Workbooks("To_be_used_with_macro1_doc1.xlsm").Worksheets("Sheet1").Range("A2").Value, _
    Received_col_range, "<>" & "", _
    Closed_col_range, ">=" & start_date1, _
    Closed_col_range, "<=" & end_date1)

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error trying to use vba countifs function

    All the ranges in CountIf(s) have to be the same size, just as when used on a worksheet.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: error trying to use vba countifs function

    thanks.......for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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