Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:20:04+00:00 2026-06-06T02:20:04+00:00

I apologize for the newb question but have not found a solution online. I

  • 0

I apologize for the newb question but have not found a solution online. I am trying to do a simple if-then statement on date ranges in VBA. My code (not working) thus far:

            LR = 52
            Set rngData = Range("D2:D" & LR)
            'define the data range to evaluate
            For Each rngCell In rngData
                Select Case rngCell.Value
                    Case Val(Range("'Some_dates'!O8").Value) To Val(Range("'Some_dates'!P8").Value): rngCell.Value = Range("'Some_dates'!N8").Value
                    Case Val(Range("'Some_dates'!O9").Value) To Val(Range("'Some_dates'!P9").Value): rngCell.Value = Range("'Some_dates'!N9").Value
                    Case Val(Range("'Some_dates'!O10").Value) To Val(Range("'Some_dates'!P10").Value): rngCell.Value = Range("'Some_dates'!N10").Value
                    Case Val(Range("'Some_dates'!O11").Value) To Val(Range("'Some_dates'!P11").Value): rngCell.Value = Range("'Some_dates'!N11").Value
                Case Else: rngCell.Value = "Outside date ranges"
                End Select
            Next rngCell

The output for all the cells is “Outside date ranges”, which means it is choosing the “else” value for all the cells in rngData, which is incorrect.

Cells O8:P11 in the ‘Some_dates’ worksheet define four date ranges (start is column O and end is column P). These are dates that can look like numbers or dates depending on how you format the cell. Column N in the ‘Some_dates’ worksheet has labels for each date range.

Any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:20:06+00:00Added an answer on June 6, 2026 at 2:20 am

    If everything you are comparing is dates, then Val is the problem. Val(1/1/2012), where 1/1/2012 is a “real” Excel date (or a fake one for that matter) returns “1”. Val returns the beginning of a string up to the first non-numeric character. So, try:

    Case Range("'Some_dates'!O8").Value To Range("'Some_dates'!P8").Value: rngCell.Value = Range("'Some_dates'!N8").Value
    

    Your code should work when the dates are stored in General or Number format, as then Val returns the entire number (string).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize in advance if this is a newb question, but what are some
I apologize in advance for this newb question, but I've been struggling with the
I apologize if this is a dumb or simple question, and I have tried
I apologize in advance for not knowing how to better state this question. In
I apologize if this question was already asked but I can't seem to find
I apologize for the silliness of the question but am a complete neophyte with
I apologize in advance if my question is not clear, because I don't know
I apologize for asking such a dumb question but my linux server is stuck
I apologize in advanced if this is somewhat of a noob question but I
I apologize since this might be a common question, but I think I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.