+ Reply to Thread
Results 1 to 2 of 2

Using If statements with multiple dates and hiding rows

  1. #1
    Registered User
    Join Date
    03-13-2021
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    12

    Using If statements with multiple dates and hiding rows

    Not sure if I should type the whole problem or just what I need help working with. I'll just go with the whole problem to see if someone can help me out.
    Basically I made a worksheet that can calculate my fortnightly paycheck. Right now I can only calculate one pay period at a time (14 days) but I want to be able to see past pay periods as well based on the starting date cell. For example when I enter the pay period is between 2nd of July and 16th of July, I want excel to calculate the pay for that period and not only that, I also want to hide rows that are not between 2nd July and 16th.

    So far I have this to hide the unnecessary rows:

    Sub HdeRow()
    ThisWorkbook.Worksheets("Kitchen").Rows("2:127").Hidden = True
    ThisWorkbook.Worksheets("Cleaning").Rows("2:127").Hidden = True
    ThisWorkbook.Worksheets("Touchpoint").Rows("2:127").Hidden = True

    If ThisWorkbook.Worksheets("Payslip").Range("B19").Value = "07/06/2021" Then
    ThisWorkbook.Worksheets("Kitchen").Rows("2:15").Hidden = False
    ThisWorkbook.Worksheets("Cleaning").Rows("2:15").Hidden = False
    ThisWorkbook.Worksheets("Touchpoint").Rows("2:15").Hidden = False

    ElseIf ThisWorkbook.Worksheets("Payslip").Range("B19").Value = "21/06/2021" Then
    ThisWorkbook.Worksheets("Kitchen").Rows("16:17").Hidden = False
    ThisWorkbook.Worksheets("Cleaning").Rows("16:17").Hidden = False
    ThisWorkbook.Worksheets("Touchpoint").Rows("16:17").Hidden = False
    'ElseIf..... continuing for the whole year but thats takes a lot of time'
    End If
    End Sub


    Any help would be hugely appreciated!

    Also I was wondering how to do a range for dates, like from 16/4/21 To 30/4/21. How do you say "If this cell is between 'this date' and 'that date' Then dont hide this row.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Using If statements with multiple dates and hiding rows

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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. Help with multiple IF statements to calculate dates
    By miyoung5877 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-01-2019, 05:39 AM
  2. [SOLVED] Hiding and Unhiding rows based on their dates VBA
    By jecowher1 in forum Excel General
    Replies: 4
    Last Post: 10-15-2015, 07:24 PM
  3. Hiding and Unhiding rows based on their dates VBA
    By jecowher1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2015, 02:11 PM
  4. [SOLVED] Index/ if statements with multiple dates/ conditions
    By lejanco in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-13-2014, 03:25 PM
  5. Hiding Rows Using If Then and If Then Else Statements - Help!
    By JenRR in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2013, 12:35 PM
  6. Hiding multiple rows
    By caliskier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2011, 05:46 PM
  7. Hiding Rows using If Statements
    By jjayredd30 in forum Excel General
    Replies: 6
    Last Post: 03-20-2009, 09:08 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