Jeg har det problem i et af mine ark; - at jeg gerne vil have to Worksheet_Change macroer ind:
I mit ark, vil jeg gerne have de to macroer her:
a) Private Sub Worksheet_Change(ByVal Target As Range) Dim r As Range If Target.Count > 1 Then End Sub If Not Intersect(Target, Range("E:E")) Is Nothing Then Application.EnableEvents = False Set r = Sheets("AllocationTypes").Range("A:A").Find(What:=Target.Value) If Not r Is Nothing Then r.Offset(0, 3).Resize(1, 49).Copy Destination:=Target.Offset(0, 2) End If
Application.EnableEvents = True End If End Sub
b) Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("BD24:BD321")) Is Nothing Then Exit Sub For Each c In Range("BD24:BD321") Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 0 If c.Value = "Internal" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 1 If c.Value = "p" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 6 If c.Value = "u" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 46 Next Range("A1").Select End Sub
Hvordan slår jeg det sammen til en macro, fordi jeg kan vist kun have et Worksheet_Change i mit ark :-(
Private Sub Worksheet_Change(ByVal Target As Range) Dim r As Range If Target.Count < 2 Then If Not Intersect(Target, Range("E:E")) Is Nothing Then Application.EnableEvents = False Set r = Sheets("AllocationTypes").Range("A:A").Find(What:=Target.Value) If Not r Is Nothing Then r.Offset(0, 3).Resize(1, 49).Copy Destination:=Target.Offset(0, 2) End If Application.EnableEvents = True End If End If If Intersect(Target, Range("BD24:BD321")) Is Nothing Then Exit Sub For Each c In Range("BD24:BD321") Range("B" & c.Row & ":BC" & c.Row).Interior.ColorIndex = 0 If c.Value = "Internal" Then Range("B" & c.Row & ":BC" & c.Row).Interior.ColorIndex = 1 If c.Value = "p" Then Range("B" & c.Row & ":BC" & c.Row).Interior.ColorIndex = 6 If c.Value = "u" Then Range("B" & c.Row & ":BC" & c.Row).Interior.ColorIndex = 46 Next Range("A1").Select
hvis du stadig mangler hjælp til den, så prøv denne:
Private Sub Worksheet_Change(ByVal Target As Range) Dim r As Range If Target.Count > 1 Then If Intersect(Target, Range("BD24:BD321")) Is Nothing Then Exit Sub For Each c In Range("BD24:BD321") Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 0 If c.Value = "Internal" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 1 If c.Value = "p" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 6 If c.Value = "u" Then Range("B" & c.row & ":BC" & c.row).Interior.ColorIndex = 46 Next Range("A1").Select end if
If Not Intersect(Target, Range("E:E")) Is Nothing Then Application.EnableEvents = False Set r = Sheets("AllocationTypes").Range("A:A").Find(What:=Target.Value) If Not r Is Nothing Then r.Offset(0, 3).Resize(1, 49).Copy Destination:=Target.Offset(0, 2) End If
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.