Results 1 to 4 of 4

Thread: [Resolved] If/Then Woes.. help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    4

    [Resolved] If/Then Woes.. help!

    I am trying to implement a if/then statement on the excel spreadsheet macro but it get errors, what am I doing wrong? I want the macro to only run between the hrous of 6:30am and 1:00pm. If it is not between those times then it should exit the macro. If it is between those hours then the macro should start. Any advice? Thanks in advance.

    Guy
    VB Code:
    1. Sub IntraData()
    2.    
    3. i = Hour(Time)
    4.  
    5. If i > 6 Then
    6. If i < 13 Then
    7.  
    8.     Set b = Selection
    9.     ad = b.Address
    10.    
    11.     dTime = Now + TimeValue("00:15:00")
    12.     Application.OnTime dTime, "IntraData"
    13.  
    14.     Sheets("Intraday").Select
    15.     Rows("2:2").Select
    16.     Selection.Insert Shift:=xlDown
    17.     Range("D1").Select
    18.     Selection.Copy
    19.     Range("A2").Select
    20.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    21.         :=False, Transpose:=False
    22.     Sheets("G&I").Select
    23.     Range("X168").Select
    24.     Application.CutCopyMode = False
    25.     Selection.Copy
    26.     Sheets("Intraday").Select
    27.     Range("B2").Select
    28.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    29.         :=False, Transpose:=False
    30.     Sheets("Growth").Select
    31.     Range("Y116").Select
    32.     Application.CutCopyMode = False
    33.     Selection.Copy
    34.     Sheets("Intraday").Select
    35.     Range("C2").Select
    36.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    37.         :=False, Transpose:=False
    38.     Sheets("G&I Summary").Select
    39.  
    40.     Range(ad).Select
    41.  
    42. End If
    43.  
    44. End Sub


    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by GuyGadois; Sep 27th, 2005 at 05:52 PM.

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: If/Then Woes.. help!

    hmmmmmmm.........which language is this??????
    Show Appreciation. Rate Posts.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: If/Then Woes.. help!

    Moved from ClassicVb.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: If/Then Woes.. help!

    You have 2 "IF" statements but only 1 "End IF".

    Changing

    VB Code:
    1. If i > 6 Then
    2. If i < 13 Then
    to
    VB Code:
    1. If i > 6 And i < 13 Then

    should solve your problem.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width