Transferring textbox values to specific cells based on multiple combo box values (VBA)

halshion

New Member
Joined
Jan 9, 2023
Messages
16
Office Version
  1. 2013
Platform
  1. Windows
Greetings everyone.

I would like to request some assistance on how to transfer Samples 1-5 userform values to their respective cells. I can only do a simple "If-Then" although I have a month's worth of data it would make the code somewhat long. Maybe there's a code that can transfer based on what array their respective combo box values are. Sorry for my bad English, this is not my native language. I'm a beginner and I would appreciate greatly if anyone's willing to teach me.
1673327597590.png


The code as of now, is as follows:
VBA Code:
Private Sub OKButton_Click()

'activate and submit data
Dim wb As Workbook
Set wb = Workbooks(Machine1.Value & ".xlsx")
wb.Activate
With wb.Sheets(Me.DimensionBox1.Text)

If Len(Data1.Text) > 0 Then .Range("C39").Value = Data1.Value
If Len(Data2.Text) > 0 Then .Range("C40").Value = Data2.Value
If Len(Data3.Text) > 0 Then .Range("C41").Value = Data3.Value
If Len(Data4.Text) > 0 Then .Range("C42").Value = Data4.Value
If Len(Data5.Text) > 0 Then .Range("C43").Value = Data5.Value
' etc
End With
wb.Activate
'make workbook visible from machine1_change invisibility
wb.Windows(1).Visible = True
wb.Save
wb.Close
End Sub
VBA Code:
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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