Thema Datum  Von Nutzer Rating
Antwort
Rot Dropdownliste bei Zeileneintrag hinzufügen/löschen
04.04.2014 08:58:05 Corina
NotSolved
04.04.2014 15:22:16 H27
**
NotSolved
04.04.2014 16:16:53 Gast87997
NotSolved
04.04.2014 16:19:20 Gast33135
*****
Solved
04.04.2014 16:50:05 Corina
NotSolved
04.04.2014 16:58:29 Gast33135
NotSolved
04.04.2014 17:01:18 Gast33135
NotSolved
04.04.2014 19:01:14 Gast24122
NotSolved
04.04.2014 21:56:16 Gast5116
NotSolved
07.04.2014 08:21:26 Corina
NotSolved

Ansicht des Beitrags:
Von:
Corina
Datum:
04.04.2014 08:58:05
Views:
2874
Rating: Antwort:
  Ja
Thema:
Dropdownliste bei Zeileneintrag hinzufügen/löschen

Hallo allerseits,

ich bin neu in diesem Forum und zudem blutige VBA-Anfängerin. Hoffe, dass ihr mir bei meine Problem behilflich sein könnt. Knabbere schon seit gestern daran rum, aber der Code den ich zusammengeschustert habe funktioniert leider nicht.

Ich möchte, dass in einem Worksheet in Spalte D einer jeden Zeile eine vordefinierte Dropdownliste zur Auswahl erscheint, sobald in Spalte C derselben Zeile etwas eingegeben wurde (egal ob Text oder Zahl)... Des Weiteren soll, sobald Einträge aus C gelöscht wurden, die Dropdownliste aus D entfernt weden. Habe bisher folgenden Code, der aber nicht funktioniert:

Private Sub Drop_Down()
    Dim SheetName As String ' Sheet containing the dropdown list
    Dim ListName As String ' Name of the range containing the validations
    Dim cColumn As String ' This is the column that contains the cause
    Dim VColumn As String ' This is the column that contains the validation
    Dim StartRow As Long ' This is the row that contains the first validation
    Dim EndRow As Long ' Last row of data
    Dim MyCell As Range ' Cell reference value
    Dim kRow As Long ' counter

' Plan of approach - make a dropdown list in the first cell
' Copy validation
' Go down list and remove validation on cells that don't need it

SheetName = "Lists"
ListName = "Drivers"
cColumn = "C"
VColumn = "D"
StartRow = 6
EndRow = 160 'Automatically identify the last row

Sheets("Risk Category Checklist").Select ' Create the validation in the first cell
    Set MyCell = Range(VColumn & StartRow)
    MakeValidationList MyCell, ListName
        MyCell.Select
        Selection.Copy ' copy this validation all the way down
        Range(VColumn & StartRow & ":" & VColumn & EndRow).Select
        Selection.PasteSpecial Paste:=xlPasteValidation, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        
' Go down the column and turn off validations for cells that don't have a text in column C
For kRow = StartRow To EndRow("C", "Risk Category Checklist")
     If Cells(kRow, cColumn).Value = "" Then
        Set MyCell = Range(VColumn & kRow)
        RemoveValidation MyCell
    End If
Next

End Sub

Sub MakeValidationList(MyCellRef As Range, ListName As String)
    With MyCellRef.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=" & ListName
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub
Sub RemoveValidation(MyCellRef As Range)
    With MyCellRef.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

Schon mal vielen, vielen Dank! 

Corina

 


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
Rot Dropdownliste bei Zeileneintrag hinzufügen/löschen
04.04.2014 08:58:05 Corina
NotSolved
04.04.2014 15:22:16 H27
**
NotSolved
04.04.2014 16:16:53 Gast87997
NotSolved
04.04.2014 16:19:20 Gast33135
*****
Solved
04.04.2014 16:50:05 Corina
NotSolved
04.04.2014 16:58:29 Gast33135
NotSolved
04.04.2014 17:01:18 Gast33135
NotSolved
04.04.2014 19:01:14 Gast24122
NotSolved
04.04.2014 21:56:16 Gast5116
NotSolved
07.04.2014 08:21:26 Corina
NotSolved