Help with combobox full with dates

ColdGeorge

Active Member
Joined
Aug 21, 2012
Messages
407
Office Version
  1. 2016
Platform
  1. Windows
Hi all
I have a userform with a combobox populated with following code

VBA Code:
Private Sub UserForm_Initialize()
Dim rango, celda As Range
Set rango = Worksheets("actividad").Range("R75:R105")
For Each celda In rango
ComboBox1.AddItem celda.Value
Next celda
End Sub

Range R75:R105 is full with dates (dd/mm/yyyy), what I want to do is that when I click on a date of the combobox, for instance 01/01/2021 and when I hit the button Go. Select the cell having same date (01/01/2021). Any help will be appreciated.

ColdGeorge
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
VBA Code:
Private Sub UserForm_Initialize()
   Me.ComboBox1.list = Sheets("actividad").Range("R75:R105").Value
End Sub
and in your button code
VBA Code:
   Range("R" & Me.ComboBox1.ListIndex + 75).Select
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hi all

Now, I'm requesting your help because my comboBox's range has changed to R91:R121 and, I think this piece of code: "Range("R" & Me.ComboBox1.ListIndex + 75).Select" has to be updated and, to tell the truth, I don't know how. Any help will be appreciated.

ColdGeorge
 
Upvote 0
Just change the 75 to 91
 
Upvote 0
Solution
Hi Fluff

I already did. And, again, it works. Now, please, help me to understand how a comboBox works in order to fix this situation myself. Thanks in advance.

ColdGeorge
 
Upvote 0
The listindex property of the combo shows which item has been selected & it starts at 0 for the 1st item in the list, then 1 for the 2nd item etc.
So by adding the start row of the range to the listindex we get the relevant cell.
 
Upvote 0
Hi Fluff

I really thank you for your clear explanation. Now I got it!

ColdGeorge
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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