+ Reply to Thread
Results 1 to 6 of 6

combining codes

Hybrid View

tweety127 combining codes 01-14-2008, 12:35 PM
RobynC Hey, I'm not quite sure... 01-14-2008, 12:53 PM
tweety127 Combining Codes 01-14-2008, 01:22 PM
RobynC Hey I've made a slight... 01-15-2008, 07:02 AM
SuitedAces Private Sub... 01-17-2008, 05:08 AM
SuitedAces LOL I guess she really didn't... 01-18-2008, 06:48 PM
  1. #1
    Forum Contributor
    Join Date
    05-22-2006
    Posts
    103

    combining codes

    Hi,

    I wonder what seems to be wrong with this code, if i apply each code separately, it works but if i combine them, it doesn't...please help..thanks so much...

    rivate Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, j As Integer, x As Integer, y As Integer
    
    
    
    
    i = Target.Row
    j = Target.Column
    x = Target.Row
    y = Target.Column
    
    
    If i > 15 Then
        If j = 9 Then
            If Cells(i, 9).Value = "Yes" Then
                   Range("M" & i).Value = Date
        
        Else
            Range("M" & i).Value = ""
            End If
        End If
    Else
    
    If x > 15 Then
        If y = 7 Then
            If Cells(y, 7).Value = "Others" Then
                   Range("K" & x).Value = "Marianne Elder"
        
        Else
            Range("K" & x).Value = " "
            
            End If
        End If
    Else
    End If
    End If
    
    
    End Sub

  2. #2
    Registered User
    Join Date
    08-16-2007
    Location
    Portsmouth, UK
    Posts
    86
    Hey,

    I'm not quite sure what you are trying to do but have noticed some errors in your code that if you correct might help.

    Firstly from the following code, i and x will be the same value and j and y will be there same value, therefore you don't need both sets of variables. Alternatively if they are ment to be different you would need to ammend your code.

    i = Target.Row
    j = Target.Column
    x = Target.Row
    y = Target.Column
    From the above point it follows that the second set of calculations will never be called, since i=x.

    Also I believe you have a typo in one line where you have writed i when you mean j.

    If you midified the code as follows I think it may work.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, j As Integer
    
    i = Target.Row
    j = Target.Column
    
    If i > 15 Then
        If j = 9 Then
            If Cells(j, 9).Value = "Yes" Then
                   Range("M" & i).Value = Date
            Else
                   Range("M" & i).Value = ""
            End If
        ElseIf j = 7 Then
            If Cells(j, 7).Value = "Others" Then
                   Range("K" & i).Value = "Marianne Elder"
            Else
                   Range("K" & i).Value = " "
            End If
        End If
    End If
    
    End Sub
    I haven't tested the above code and I'm not really sure what you are trying to achieve so it may not work, but it basically just changes all the x and y values to i and j values and ensures that the secon set of code will triggar.

  3. #3
    Forum Contributor
    Join Date
    05-22-2006
    Posts
    103

    Combining Codes

    Thanks for your response.

    Here is what i am trying to do.

    if column j = yes then automatically column m = current date

    or

    if column G = others then automatically column K = "Marianne Elder"

    it doesn't follow that both condition must be satisfied...

    thanks so much

  4. #4
    Registered User
    Join Date
    08-16-2007
    Location
    Portsmouth, UK
    Posts
    86
    Hey

    I've made a slight change to the code I originally posted (the red bit). What the code should do (not tested if it doesn't work let me know) is check that the row number is greater than 15. If so it will then check if column I = "Yes" and if so put the date in column M and then it will check if column G = "Others" and if so put "Marianne Elder" in column K. The latter two tests are independant of each other which wasn't the case before

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, j As Integer
    
    i = Target.Row
    j = Target.Column
    
    If i > 15 Then
        If j = 9 Then
            If Cells(j, 9).Value = "Yes" Then
                   Range("M" & i).Value = Date
            Else
                   Range("M" & i).Value = ""
            End If
        End If
        
        If j = 7 Then
            If Cells(j, 7).Value = "Others" Then
                   Range("K" & i).Value = "Marianne Elder"
            Else
                   Range("K" & i).Value = " "
            End If
        End If
    End If
    
    End Sub
    Hope this helps and sorry for the delay in responding got sidetracked

  5. #5
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Target, Range("J1:J14")) Is Nothing Then
             If LCase(Target.Value) = "yes" Then
                   Target.Offset(0, 4).Value = Date
             Else
                   Target.Offset(0, 4).Value = " "
             End If
        End If
        
        
        If Not Intersect(Target, Range("G1:G14")) Is Nothing Then
             If LCase(Target.Value) = "others" Then
                   Target.Offset(0, 4).Value = "Marianne Elder"
             Else
                   Target.Offset(0, 4).Value = " "
             End If
        End If
        
    End Sub
    Your code will not work without capitalizing.
    I made the assumption that you did not want to require that "Yes" and "Others" need to be capitalized.
    You could eliminate the LCase function to force an exact case match.
    Last edited by SuitedAces; 01-17-2008 at 06:25 AM.

  6. #6
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310

    Thumbs down

    LOL I guess she really didn't need any help.

    I thought I saw a puddy cat , I did saw a puddy cat , I did.

+ 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