Results 1 to 7 of 7

Using InputBox to Create Date Range for COUNTIFS formula

Threaded View

  1. #1
    Registered User
    Join Date
    09-20-2022
    Location
    St. Louis, MO
    MS-Off Ver
    2016
    Posts
    3

    Question Using InputBox to Create Date Range for COUNTIFS formula

    I'm using Excel 2016.
    I am trying to figure out a way to create a formula that takes it's parameters from InputBox entries and then executes. Here's the function I'm trying to fix:


    Sub CreateCountIFSQueryFunction()
    
    Worksheets("EmpRpt").Activate
    
    Dim startDate As String
    Dim endDate As String
    Dim industry As String
    
    startDate = InputBox(Prompt:="Enter the Start Date", Title:="Date Range", Default:="01/01/1980")
    endDate = InputBox(Prompt:="Enter the End Date", Title:="Date Range", Default:="12/31/2030")
    industry = InputBox(Prompt:="Which Industry Are You Interested In?", Title:="Choose Industry", Default:="Name")
    
    Range("C30").Select
    Range("C30").Value = startDate
    Range("D30").Value = endDate
    Range("E30").Value = industry
    Range("G30").Select
    ActiveCell.FormulaR1C1 = _
    "=COUNTIFS(Employment!R2C3:R[477]C[-4],R30C3,Employment!R2C3:R[477]C[-4],R30C4,Employment!R2C7:R[477]C,R30C5)"
    End Sub
    This formula works fine if you hardcode the dates. Example:
    =COUNTIFS(Employment!$C$2:C502,">=8/1/2022",Employment!$C$2:C502,"<=08/31/2022",Employment!$G$2:G502,"Factory")
    This formula is being executed from the "EmpRpt" sheet. I need this formula to count the number of entries on the "Employment" sheet with dates that range from "startDate" to "endDate" where the column labeled "Industry" is the value entered for "industry". I've tried getting the ">=" and "<=" operators into the formula, but nothing seems to be working.

    Am I going about this the wrong way?
    Last edited by nastarius; 09-20-2022 at 10:54 AM. Reason: Add Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. create array using inputbox range(s) plus row count from elsewhere
    By Coley356 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2022, 02:10 PM
  2. Help with date range within COUNTIFS formula
    By pptdgc1999 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-28-2021, 01:07 AM
  3. Countifs with date range formula Broke
    By rogrand in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2020, 02:56 PM
  4. Countifs match criteria and date is equals to or within date range
    By tiggi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-28-2016, 11:00 AM
  5. [SOLVED] Help with InputBox for Date Range
    By george.arnold in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2015, 12:19 PM
  6. Replies: 2
    Last Post: 05-28-2014, 06:52 AM
  7. Using Date Range in Countifs formula
    By Kenny_D in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-09-2010, 10:57 AM

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