+ Reply to Thread
Results 1 to 36 of 36

Quicker way to enter in multiple vba if statements

Hybrid View

  1. #1
    Registered User
    Join Date
    02-27-2005
    Posts
    35
    ?
    Could you elaborate a little more?
    I need it so if something is entered into one of the days, that will be the info used, but when the next month comes, when i redo the schedule i need the formula back without having to retype it.

    With the 2 sheets, the request off and the final this isnt a problem but I am trying to eliminate the request off sheet, so when I do the schedule for the following month, the formulas return when i clear the cells.
    for example say in c5 i put in vac, next month when i do the schedule in c5 i need to be able to clear cell c5 and have it use the data from t5.
    Liek i said with the 2 sheets this isnt a problem, but i would liek to get it down to just one.
    Thanks.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    Quote Originally Posted by jubangy
    ?
    Could you elaborate a little more?
    I need it so if something is entered into one of the days, that will be the info used, but when the next month comes, when i redo the schedule i need the formula back without having to retype it.

    With the 2 sheets, the request off and the final this isnt a problem but I am trying to eliminate the request off sheet, so when I do the schedule for the following month, the formulas return when i clear the cells.
    for example say in c5 i put in vac, next month when i do the schedule in c5 i need to be able to clear cell c5 and have it use the data from t5.
    Liek i said with the 2 sheets this isnt a problem, but i would liek to get it down to just one.
    Thanks.
    Very strange, I thought I attached a code to this thread..
    anyway...

    Try this
    Sub YouKnow()
        Dim r As Range
        Dim c As Range
        Set r = Range("H1", Range("H65536").End(xlUp))
        For Each c In r.Cells
            If c <= 0 Then
                c = c.Offset(0, 1)
            End If
        Next c
    End Sub

  3. #3
    Registered User
    Join Date
    02-27-2005
    Posts
    35
    Quote Originally Posted by davesexcel
    Very strange, I thought I attached a code to this thread..
    anyway...

    Try this
    Sub YouKnow()
        Dim r As Range
        Dim c As Range
        Set r = Range("H1", Range("H65536").End(xlUp))
        For Each c In r.Cells
            If c <= 0 Then
                c = c.Offset(0, 1)
            End If
        Next c
    End Sub
    Thankyou Davesexcel, but that is not doing anything.
    Maybe this will help describe what I am trying to do alittle better,

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("c5").Value <= 0 Then
    Range("c5") = Range("t5")
    End If
    
    If Range("d5").Value <= 0 Then
    Range("d5") = Range("u5")
    End If
    
    If Range("e5").Value <= 0 Then
    Range("e5") = Range("v5")
    End If
    
    If Range("f5").Value <= 0 Then
    Range("f5") = Range("w5")
    End If
    
    If Range("c6").Value <= 0 Then
    Range("c6") = Range("t6")
    End If
    
    If Range("d6").Value <= 0 Then
    Range("d6") = Range("u6")
    End If
    
    If Range("e6").Value <= 0 Then
    Range("e6") = Range("v6")
    End If
    
    If Range("f6").Value <= 0 Then
    Range("f6") = Range("w6")
    End If
    
    
    
    End Sub
    This so far works, except I need it to go down to row35.
    Thanks again.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    What do you mean it doesn't do anything??

    Try placing the code in the worksheet change then

    BTW
    Your new example is nothing like your original example,

  5. #5
    Registered User
    Join Date
    02-27-2005
    Posts
    35
    Quote Originally Posted by davesexcel
    What do you mean it doesn't do anything??

    Try placing the code in the worksheet change then

    BTW
    Your new example is nothing like your original example,
    In the new example I just changed the cell ranges to the ones I am using.
    Also, I did try your formula in worksheet change, and it keeps saying expecting end sub.

    Thanks again for your help.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim x As String, y As String
    With Range("c5:f6")
        x = .Address
        y = .Offset(,17).Address
        .Value = Evaluate("if(" & x & "<=0," & y & "," & x & ")")
    End With
    End Sub
    or
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim i As Integer
    For i = 3 To 6
        With Cells(5,i).Resize(2)
            .Value = Evaluate("if(" & .Address & "<=0," & .Offset(,17).Address & "," & .Address & ")")
        End With
    Next
    End Sub
    Last edited by jindon; 05-18-2008 at 01:31 AM.

  7. #7
    Registered User
    Join Date
    02-27-2005
    Posts
    35
    Thankyou a ton jindon, that seems to have done the trick, I am not even going to try and pretend like I understand the code, but if you wouldn't mind maybe you could explain it so I can try and get a grasp of it.
    Usually I can work my way through them and figure it out but this one makes no sense to me, however like I said it seems to be workign well. I appreciate it muchly, and thank you davesexcel for taking the time to try and help me.

+ 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