ActiveX ComboBox Default Value changeable

CJS548

New Member
Joined
Dec 11, 2013
Messages
25
Hi,
I've been struggling with this problem for awhile.
I've made a form out of ActiveX controls, vba codes etc.
I am almost zero knowledge about vba.

I've made a combo box, named cmbDate.
ListFillRange of the combo box is Q11:Q13, where there are formulas in this cells:
Q11: =TEXT(TODAY(),"dd/mm/yyyy")
Q12: =TEXT(TODAY()-1,"dd/mm/yyyy")
Q13: =TEXT(TODAY()+1,"dd/mm/yyyy")
Also, I have this code running in vba for this combo box:
Code:
 Private Sub cmbDate_Change()    ActiveSheet.cmbDate.Value = Format(ActiveSheet.cmbDate.Value, "dd/mm/yyyy")
    
End Sub
What I want is, when a user start using the form, the combo box for date will have the Q11 value in there ready, because most of the time, a user will only use today's date, and occasionally tomorrow's or yesterday's.
So if the cmbDate can be default as today's date which is at Q11, and when he wants to change the value he can simply just press down the box and pick another date, it will be much user friendly.

I've tried:
Code:
 Private Sub cmbDate_Change()    ActiveSheet.cmbDate.Value = Format(ActiveSheet.cmbDate.Value, "dd/mm/yyyy")
    cmbDate.Value = cmbDate.List(0)
End Sub
But that will not give me option to change the value if I wanted to change, and when I press other dates in the box, it will still goes to 'today'.

Please advice me!
Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This works, thanks!
ADDITIONAL QUESTION:
1:
Can the display value in the box shown as 'last selected'?
Like if i choose 'the second value' in the box now, then after i 'save and reset' the form, the value in cmbDate will still show 'the second value'? instead of keep resetting to the first value like it ran on the code?
2:
When the form been reset, the value in all the text box and combo box will be saved to another sheets call "DATA", but the cmbDate box will not copied to the sheet as date, but it show as text format, meaning the default alignment is starting on the left, not the right like any other date format should be.
This is the code i use for saving the data:
Code:
Private Sub cmdSave_Click()   
   
    Application.ScreenUpdating = False
   
    Dim iRow As Long
   
    iRow = Sheets("DATA").Range("A104857").End(xlUp).Row + 1
           
    If ValidateForm = True Then
   
        With ThisWorkbook.Sheets("DATA")
       
            .Range("A" & iRow).Value = iRow = 1
            .Range("B" & iRow).Value = txtNumber.Value
            .Range("C" & iRow).Value = cmbDate.Value
            .Range("D" & iRow).Value = txtKG.Value
            .Range("E" & iRow).Value = cmbIssuer.Value
            .Range("F" & iRow).Value = txtSorter.Value
            .Range("G" & iRow).Value = txtZone.Value
       
        End With
        Call Reset
    Else
        Application.ScreenUpdating = True
        Exit Sub
    End If
       
        Application.ScreenUpdating = True
       
End Sub

Hi
I try this but not functioned

Private Sub cmdSave_Click()

Application.ScreenUpdating = False

Dim iRow As Long

iRow = Sheets("DATA").Range("A104857").End(xlUp).Row + 1

If ValidateForm = True Then

With ThisWorkbook.Sheets("DATA")

.Range("A" & iRow).Value = iRow = 1
.Range("b" & iRow).Value = TextBox2.Value
.Range("c" & iRow).Value = ComboBox1.Value
.Range("d" & iRow).Value = TextBox4.Value
.Range("e" & iRow).Value = TextBox3.Value
.Range("f" & iRow).Value = ComboBox2.Value
.Range("d" & iRow).Value = TextBox5.Value
.Range("g" & iRow).Value = TextBox6.Value
.Range("h" & iRow).Value = TextBox7.Value
.Range("i" & iRow).Value = TextBox8.Value
.Range("j" & iRow).Value = TextBox9.Value
.Range("k" & iRow).Value = TextBox10.Value
.Range("l" & iRow).Value = ComboBox3.Value

End With
Call Reset
Else
Application.ScreenUpdating = True
Exit Sub
End If

Application.ScreenUpdating = True

End Sub
 

Attachments

  • Save.PNG
    Save.PNG
    39.4 KB · Views: 11
Upvote 0
Hi
I try this but not functioned

Private Sub cmdSave_Click()

Application.ScreenUpdating = False

Dim iRow As Long

iRow = Sheets("DATA").Range("A104857").End(xlUp).Row + 1

If ValidateForm = True Then

With ThisWorkbook.Sheets("DATA")

.Range("A" & iRow).Value = iRow = 1
.Range("b" & iRow).Value = TextBox2.Value
.Range("c" & iRow).Value = ComboBox1.Value
.Range("d" & iRow).Value = TextBox4.Value
.Range("e" & iRow).Value = TextBox3.Value
.Range("f" & iRow).Value = ComboBox2.Value
.Range("d" & iRow).Value = TextBox5.Value
.Range("g" & iRow).Value = TextBox6.Value
.Range("h" & iRow).Value = TextBox7.Value
.Range("i" & iRow).Value = TextBox8.Value
.Range("j" & iRow).Value = TextBox9.Value
.Range("k" & iRow).Value = TextBox10.Value
.Range("l" & iRow).Value = ComboBox3.Value

End With
Call Reset
Else
Application.ScreenUpdating = True
Exit Sub
End If

Application.ScreenUpdating = True

End Sub
 

Attachments

  • Save2.PNG
    Save2.PNG
    44.7 KB · Views: 12
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top