abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
I have this code works well but if anybody help exchange this code with another code using array
I have many combobox and textbox it takes more time if I write each active x (combobox & textbox)
so what i want when get in array about combobox & textbox like this
this is my code
thanks in advance
I have this code works well but if anybody help exchange this code with another code using array
I have many combobox and textbox it takes more time if I write each active x (combobox & textbox)
so what i want when get in array about combobox & textbox like this
Code:
' 3 combobox in array
for i = 1 to 3
'array(1,2,3) it means copying to column a,b,c as in my code
("combobox" & i) = array(1,2,3)
'3 textbox in array
for s=1 to 3
'array(4,5,6)it means copying to column d,e,f as in my code
("textbox" & s) =array(4,5,6)
VBA Code:
Private Sub CommandButton1_Click()
Dim lr1, lr2 As Integer
Dim wk1, wk2 As Worksheet
Set wk1 = Sheets("expirity")
Set wk2 = Sheets("NEW")
lr1 = wk1.Range("a" & Rows.Count).End(xlUp).Row + 1
lr2 = wk2.Range("a" & Rows.Count).End(xlUp).Row + 1
If OptionButton1.Value = True Then
With wk1
.Range("a" & lr1) = Me.ComboBox1.Value
.Range("b" & lr1) = Me.ComboBox2.Value
.Range("c" & lr1) = Me.ComboBox3.Value
.Range("d" & lr1) = Me.TextBox1.Value
.Range("e" & lr1) = Me.TextBox2.Value
.Range("f" & lr1) = Me.TextBox3.Value
End With
Else
With wk2
.Range("a" & lr2) = Me.ComboBox1.Value
.Range("b" & lr2) = Me.ComboBox2.Value
.Range("c" & lr2) = Me.ComboBox3.Value
.Range("d" & lr2) = Me.TextBox1.Value
.Range("e" & lr2) = Me.TextBox2.Value
.Range("f" & lr2) = Me.TextBox3.Value
End With
End If
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox3.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
End Sub
thanks in advance