1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Excel Macro Explanation

Discussion in 'Business Applications' started by computerman29642, Oct 7, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Could someone explain the code below?

    Code:
    Cells(8, Weekday(Date) + 2).Select
    
    I understand that the code is looking at the 8th row, but I am a little confused on the ColumnIndex.
     
  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Weekday(Date) gives you a value from 1 to 7 according to the current day according to the PC clock. Since return type isn't specified, the default (Sunday = 1, Monday = 2, etc.) is used.

    So if run today (Oct 7th 2008), weekday = Tuesday, i.e. 3. The +2 gives you 5, so the outcome is E8 selection.

    Presumably there's other "stuff" in the first 7 rows/2 columns that's to be ignored. Other than that, actual selection may not be necessary depending on what goes before/comes next.

    HTH
     
  3. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Thanks Bomb. That helps a great deal.
     
  4. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,452
    Two questions I have looking at that one line. Might be nothing, might be something.

    Code:
    Cells(8, Weekday(Date) + 2).Select
    The range is not qualified as far as a sheet/book goes. And you're using Select. Ugh. Tell me you have a specific need to select something? :)

    Okay, off soap box. :D
     
  5. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    LOL....

    Yes, I have a specific need to select something. All the code does is select the current date/weekday so I can input my total hours of work. This code is used for my timesheet.
     
  6. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,452
    Okay... this time... ;)
     
  7. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    LOL...I was sweating there for a moment....
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/756927

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice