• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combining 2 Macros

Dokat

Member
Hi,

I have 2 macros that i'd like to combine. Please see below. Can someone help? Thanks

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
   
    Set KeyCells = Range("CE1")
      Dim r1 As Range, r2 As Range
      Set r1 = Range("CE1")
      Set r2 = Range("D5")
      If r1.Value = 1 Then
      r2.Interior.Color = vbWhite
      Else
      r2.Interior.Color = 6
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
   
    Set KeyCells = Range("CF1")
      Dim r1 As Range, r2 As Range
      Set r3 = Range("CF1")
      Set r4 = Range("D5")
      If r1.Value = 1 Then
      r2.Interior.Color = vbWhite
      Else
      r2.Interior.Color = 6
End If
End Sub
 
Try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r1 As Range, r2 As Range, r3 As Range

    Set r1 = Range("CE1")
    Set r2 = Range("CF1")
    Set r3 = Range("D5")

    If r1.Value = 1 Or r2.Value = 1 Then
        r2.Interior.Color = vbWhite
    Else
        r3.Interior.Color = 6
    End If
End Sub
 
Hi,

I tried the code however it didnt work. It didnt change the color coding.

Thanks


Try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r1 As Range, r2 As Range, r3 As Range

    Set r1 = Range("CE1")
    Set r2 = Range("CF1")
    Set r3 = Range("D5")

    If r1.Value = 1 Or r2.Value = 1 Then
        r2.Interior.Color = vbWhite
    Else
        r3.Interior.Color = 6
    End If
End Sub
 
Made some modificantions to teh code and its working now.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r1 As Range, r2 As Range, r3 As Range
    Set r1 = Range("CE1")
    Set r2 = Range("CF1")
    Set r3 = Range("D5")
    Set r4 = Range("E5")
    If r1.Value = 1 Then
        r3.Interior.Color = vbWhite
    ElseIf r2.Value = 1 Then
        r4.Interior.Color = vbWhite
    Else
        r3.Interior.Color = 6
    End If
End Sub


Hi,

I tried the code however it didnt work. It didnt change the color coding.

Thanks
 
Back
Top