halshion
New Member
- Joined
- Jan 9, 2023
- Messages
- 16
- Office Version
- 2013
- Platform
- 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.
The code as of now, is as follows:
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
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.
The code as of now, is as follows:
VBA Code:
'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: