Using vba to go to column with current week
Results 1 to 7 of 7

Thread: Using vba to go to column with current week
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Using vba to go to column with current week

    Hi there,Sorry if I am posting a new thread and it has already been answered else where. I have looked and looked, but no luck so far.I have a time & resource planning tool which has fixed data on columns A to G (name , activity , priority etc). From H on wards are week to week columns.What I am trying to do is get the current week to pop up first and scroll all the way to the left. This means that past planning information is not stuck between the fixed columns (A to G) and the current and future relevant weeks. So I thought I managed to crack this by using the following VBA code:Sub gotoDate ()Dim c As RangeDim d As Dated = Date For Each c In Range("H4:AT4") If c = d Then Application.Goto c, True End If Next cEnd SubThis worked/ works beautifully if we are on the actual date today that is shown on the sheet. So for example, my week to week inputs are 19-Aug-19, 26-Aug-19, 02-Sep-19 and so on. The sheet will only go to the 19-Aug-19 week column if it is the 19-Aug-19. What I am looking to do is essentially what I have, but add a further range for that week instead. Can anyone help me out? Thanks,D

  2. #2
    Board Regular
    Join Date
    Apr 2019
    Posts
    79
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using vba to go to column with current week

    Please use CODE tag around vba code. Now it's hard to read really.

  3. #3
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,456
    Post Thanks / Like
    Mentioned
    54 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Using vba to go to column with current week

    Welcome to the Board!

    As Koksek mentioned, your code is basically unreadable, as it is appearing as one long string.
    Here are instructions on how to post your code so it appears in a readable format: https://www.mrexcel.com/forum/board-...-vba-code.html
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,058
    Post Thanks / Like
    Mentioned
    461 Post(s)
    Tagged
    46 Thread(s)

    Default Re: Using vba to go to column with current week

    Hi & welcome to MrExcel.
    How about
    Code:
    d = Date - Weekday(Date, vbMonday) + 1
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using vba to go to column with current week

    Hi there, First Noob move on my first post. hope this works.

    Sorry if I am posting a new thread and it has already been answered else where. I have looked and looked, but no luck so far.I have a time & resource planning tool which has fixed data on columns A to G (name , activity , priority etc). From H on wards are week to week columns.What I am trying to do is get the current week to pop up first and scroll all the way to the left.
    This means that past planning information is not stuck between the fixed columns (A to G) and the current and future relevant weeks. So I thought I managed to crack this by using the following VBA

    Code:
    Sub gotoDate ()
    Dim c As Range
    Dim d As  Date
    d = Date
        For Each c In Range("H4:AT4")        
    If c = d Then             
    Application.Goto c, True        
    End If    
    Next c
    End Sub
    This worked/ works beautifully if we are on the actual date today that is shown on the sheet. So for example, my week to week inputs are 19-Aug-19, 26-Aug-19, 02-Sep-19 and so on. The sheet will only go to the 19-Aug-19 week column if it is the 19-Aug-19. What I am looking to do is essentially what I have, but add a further range for that week instead. Can anyone help me out? Thanks,D

  6. #6
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using vba to go to column with current week

    Amazing Fluff, this worked !! don't know how but amazing ! thank you !!

  7. #7
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,058
    Post Thanks / Like
    Mentioned
    461 Post(s)
    Tagged
    46 Thread(s)

    Default Re: Using vba to go to column with current week

    You're welcome & thanks for the feedback.
    This part
    Code:
    Weekday(Date, vbMonday)
    returns the day of the week starting with Monday as 1, so for today it returns 3
    That is then subtracted from today's date to give 18/8/19 & then we add 1 to bring it back to Mondays date, the 19th
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •