+ Reply to Thread
Results 1 to 4 of 4

checking for empty values and using offset

  1. #1
    Registered User
    Join Date
    03-28-2007
    Posts
    27

    checking for empty values and using offset

    Hey Guys,
    I'm trying to write an if and statement in VBA to reference columns 15 and 16 (using offset) and tell them that if they are both empty that the interior color needs to stay empty in both.
    here is what i have but it isn't working:

    Please Login or Register  to view this content.
    Sub mondaytry()
    Range("b4:b341").Name = "dashboard"
    Range("I1").Name = "today"
    For Each cell In Range("dashboard")
    If cell.Offset(0, 16) = Range("today") Then cell.Offset(0, 16).Interior.ColorIndex = 8
    Next

    For Each cell In Range("dashboard")
    If IsEmpty(cell.Offset(0, 15)) And IsEmpty(cell.offest(0, 16)) Then
    cell.Offset(0, 15).Interior.ColorIndex = 9
    cell.Offset(0, 16).Interior.ColorIndex = 9
    End If
    Next

    End Sub
    Please Login or Register  to view this content.
    Any Thoughts as to how i can fix it?
    THanks,
    Rytis
    Last edited by ritz; 04-23-2007 at 05:35 PM. Reason: forgot to wrap code

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    ritz,

    Please read forum rules below and then wrap your code

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Ritz,

    The Offset method of Range object starts at the refrence cell. Rows move down with postive values and move up with a negative values. Columns move left with positive values and move to the right with negatve values.

    You are start in column "B4". Offset(0, 1) would then reference cell "C4". Your code references Offset(0, 16) or cell "R4". If you want to reference cell "O4" then the offset needs to be Offset(0, 13).

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Ritz,

    Your first post and second post are different, so I am not sure what you really want to do. If the cell in column 16 is the controlling value that determines if column 15's color changes, your code would be this...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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