Results 1 to 3 of 3

Correct syntax in If Then statement to make 2 things happen if condition met

Threaded View

coasterman Correct syntax in If Then... 12-19-2011, 12:02 PM
Kyle123 Re: Correct syntax in If Then... 12-19-2011, 12:16 PM
coasterman Re: Correct syntax in If Then... 12-19-2011, 12:55 PM
  1. #1
    Registered User
    Join Date
    04-22-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    59

    Correct syntax in If Then statement to make 2 things happen if condition met

    This will doubtless turn out to be a typical Noob question but here goes.

    I have some code which will tidy up a user input form based on the number of periods selected in F4 but I also want to place the value in G22 into a specified row (obviously not one of those already cleared by the first Then action) without having to duplicate the If statement as a separate line of code.

    I've included the code. Ive included the bit that doesnt work in the first If statement just to give an alternative description of what I am trying to achieve. Hope this makes sense

    Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Range("F4").Value = 1 Then Range("Q21:Q40,D21:D39").ClearContents , Range("D19").Value = Range("G22")
        If Range("F4").Value = 2 Then Range("Q23:Q40,D23:D39").ClearContents
        If Range("F4").Value = 3 Then Range("Q25:Q40,D25:D39").ClearContents
        If Range("F4").Value = 4 Then Range("Q27:Q40,D27:D39").ClearContents
        If Range("F4").Value = 5 Then Range("Q29:Q40,D29:D39").ClearContents
        If Range("F4").Value = 6 Then Range("Q31:Q40,D31:D39").ClearContents
        If Range("F4").Value = 7 Then Range("Q33:Q40,D33:D39").ClearContents
        If Range("F4").Value = 8 Then Range("Q35:Q40,D35:D39").ClearContents
        If Range("F4").Value = 9 Then Range("Q37:Q40,D37:D39").ClearContents
        If Range("F4").Value = 10 Then Range("Q39:Q40,D39").ClearContents
    End Sub
    Thanks
    Last edited by coasterman; 12-19-2011 at 01:53 PM.

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