Thema Datum  Von Nutzer Rating
Antwort
06.06.2014 12:47:52 Corina
NotSolved
06.06.2014 14:32:26 Amicro2000
NotSolved
06.06.2014 14:56:37 Gast15358
NotSolved
06.06.2014 15:17:35 Amicro2000
NotSolved
10.06.2014 09:00:57 Corina
NotSolved
Blau Code läuft nicht, keine Fehlermeldung
10.06.2014 09:00:58 Corina
NotSolved
11.06.2014 21:55:31 Hmm..Hmm..
*****
Solved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 21:54:18 Hmm..Hmm..
*****
NotSolved
13.06.2014 09:49:18 Corina
NotSolved

Ansicht des Beitrags:
Von:
Corina
Datum:
10.06.2014 09:00:58
Views:
1609
Rating: Antwort:
  Ja
Thema:
Code läuft nicht, keine Fehlermeldung

Hallo allerseits,

sry für meine späte Rückmeldung. Schon mal vielen Dank für den ersten Tipp, das mit dem "On Error GoTo" hatte ich leider überlesen -.-

Nun meine ich auch zu erkennen weshalb das Set rngRef = ActiveSheet.UsedRange.Columns falsch ist. Used Range adressiert immer den gesamten Bereich, aber ich möchte immer gezielt bestimmte Spalten (C, E, J) ansprechen. Wenn was in C steht, soll in D eine DropDown-Liste zur Auswahl stehen. Das gleiche gilt für E in Kombination mit F, sowie für J mit K. Der ursprüngliche Code funktioniert, ist aber nicht sehr elegant. Daher wollte ich mit Select Case arbeiten, um ein paar Zeilen weniger zu haben.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
'Shows dropdown entries for reference columns

Application.EnableEvents = False
   
  'On Error GoTo ErrHandler
   
  Dim rngRef    As Excel.Range
  Dim rngArea   As Excel.Range
  Dim rngCells  As Excel.Range
  Dim rngCell   As Excel.Range
   
 ' react only to changes within the following range
  Set rngRef = Columns("C")
   
' check for changes
  Set rngCells = Intersect(Target, rngRef)
  If Not rngCells Is Nothing Then
     
    For Each rngArea In rngCells.Areas 'relevant for simultaneous change within several cells
    
      For Each rngCell In rngArea.Cells
         
        With Cells(rngCell.row, "D") 'cell with dropdown list
           
          If Trim$(rngCell.Value) <> "" Then
          '> changed cell contains data => delete dropdown content and set new one
            Call .Validation.Delete
            Call .ClearContents
            Call .Validation.Add(xlValidateList, Formula1:="=Drivers")
          Else
          'changed cell contains data => delete dropdown and content
            Call .Validation.Delete
            Call .ClearContents
          End If
        End With
         
      Next
    Next
     
  End If
  
  Dim rngRef2    As Excel.Range
  Dim rngArea2   As Excel.Range
  Dim rngCells2  As Excel.Range
  Dim rngCell2   As Excel.Range
    
  Set rngRef2 = Columns("E")
    
  Set rngCells2 = Intersect(Target, rngRef2)
       
  If Not rngCells2 Is Nothing Then
             
        For Each rngArea2 In rngCells2.Areas
       
            For Each rngCell2 In rngArea2.Cells
        
                With Cells(rngCell2.row, "F")
           
                    If Trim$(rngCell2.Value) <> "" Then

                        Call .Validation.Delete
                        Call .ClearContents
                        Call .Validation.Add(xlValidateList, Formula1:="=Category")
                    Else

                        Call .Validation.Delete
                        Call .ClearContents
                    End If
                End With
            Next
        Next
  End If
  
  Dim rngRef3    As Excel.Range
  Dim rngArea3   As Excel.Range
  Dim rngCells3  As Excel.Range
  Dim rngCell3   As Excel.Range
    
  Set rngRef3 = Columns("J")
    
  Set rngCells3 = Intersect(Target, rngRef3)
       
  If Not rngCells3 Is Nothing Then
             
       For Each rngArea3 In rngCells3.Areas
       
            For Each rngCell3 In rngArea3.Cells
        
                With Cells(rngCell3.row, "K")
           
                    If IsEmpty(rngCell3.Value) Then
                        Call .Validation.Delete
                        Call .ClearContents
                    Else
                        Call .Validation.Delete
                        Call .ClearContents
                        Call .Validation.Add(xlValidateList, Formula1:="=Organizational_level")
                    End If
                End With
            Next
        Next
  End If

 
SafeExit:
  Application.EnableEvents = True
  Exit Sub
  
ErrHandler:
  Call MsgBox(Err.Description, vbCritical, "Error " & Err.number)
  GoTo SafeExit
   
End Sub

 

Vielen Dank für eure Unterstützung!

VG

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
06.06.2014 12:47:52 Corina
NotSolved
06.06.2014 14:32:26 Amicro2000
NotSolved
06.06.2014 14:56:37 Gast15358
NotSolved
06.06.2014 15:17:35 Amicro2000
NotSolved
10.06.2014 09:00:57 Corina
NotSolved
Blau Code läuft nicht, keine Fehlermeldung
10.06.2014 09:00:58 Corina
NotSolved
11.06.2014 21:55:31 Hmm..Hmm..
*****
Solved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 09:09:38 Corina
NotSolved
12.06.2014 21:54:18 Hmm..Hmm..
*****
NotSolved
13.06.2014 09:49:18 Corina
NotSolved