PDA

View Full Version : [SOLVED:] VBA Input Box



CantCode
02-10-2020, 03:03 AM
Hi All,

First post so hoping for some help. I have tried various search engines and video teaching platforms and am completely stuck.

Within Excel 2016 I am trying to create a UserForm where the user selects a Project from a drop down and a date, then enters either 1,1.5 or 2. Once they click "Ok" the value would be entered in the correct cell.

I imagine this will be along the lines of an index and match formula to find the data, but I have no idea how get the 1,1.5 or 2 into the relevant cell. I have set up a user form which is linked to the relevant lists.

Please let me know if this is not clear or you need me to expand,

Thank you





10/02/2020
17/20/20


Project 1




Project 2




Project 3




...

Paul_Hossler
02-10-2020, 05:38 AM
Excel's InputBox doesn't have a DropDown capability

A Userform does

CantCode
02-10-2020, 05:46 AM
Apologies, you are correct. This is a UserForm which I have created already

Paul_Hossler
02-10-2020, 06:34 AM
Can you attach a small workbook with what you have so far?

CantCode
02-10-2020, 07:06 AM
25958

Paul_Hossler
02-10-2020, 03:44 PM
You can play with this Userform code

I didn't bind the Combobox data to the worksheet, and deleted your Named ranges

The other attachment uses radio buttons to select the time (1, 1.5, or 2)




Option Explicit


Dim rData As Range




Private Sub cbExit_Click()
Me.Hide
Unload Me
End Sub


Private Sub cbUpdate_Click()
'ComboBox lists start at 0, put values in +2
rData.Cells(Me.CBO_Project.ListIndex + 2, Me.CBO_Dates.ListIndex + 2).Value = txt_Time.Value

Call cbExit_Click


End Sub


Private Sub UserForm_Initialize()
Dim i As Long

Set rData = Worksheets("Sheet1").Cells(1, 1).CurrentRegion


With rData
For i = 2 To .Columns.Count
Me.CBO_Dates.AddItem .Cells(1, i).Value
Next i
For i = 2 To .Rows.Count
Me.CBO_Project.AddItem .Cells(i, 1).Value
Next i


End With


End Sub

CantCode
02-11-2020, 01:03 AM
Hi Paul, Genuinely can't thank you enough for this. Appreciate your help, you sir are a life saver.