Lobanovski
Gebruiker
- Lid geworden
- 6 apr 2011
- Berichten
- 15
Beste VBA-ers,
Ik heb een bestand met een combobox daarin. De datum wordt echter als getal weergegeven. Ik heb via onder andere dit forum wel codes gevonden om dat te verhelpen, maar krijg deze niet werkend in mijn macro. Onderstaand staat de macro zoals ik die nu heb voor de combobox. Wie zou mij kunnen helpen om deze zo aan te passen dat de datum ook als zodanig weer wordt gegeven?
Alvast bedankt!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("Data")
Cancel = True
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.ListFillRange = "Maand"
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
Ik heb een bestand met een combobox daarin. De datum wordt echter als getal weergegeven. Ik heb via onder andere dit forum wel codes gevonden om dat te verhelpen, maar krijg deze niet werkend in mijn macro. Onderstaand staat de macro zoals ik die nu heb voor de combobox. Wie zou mij kunnen helpen om deze zo aan te passen dat de datum ook als zodanig weer wordt gegeven?
Alvast bedankt!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("Data")
Cancel = True
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.ListFillRange = "Maand"
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub