abdo meghari
Well-known Member
- Joined
- Aug 3, 2021
- Messages
- 573
- Office Version
- 2019
Hi
I want implement this code for four sheets based on select option buttons . the optionbuttons' name are the same sheets names . so any match name for the optionbuttion is same tfor each sheet name should copy data to spicific sheet is matched with optionbutton . optionbutton1.caption="PURCHASE",optionbutton2.caption="SALES" ,optionbutton3.caption="STOCK",optionbutton4.caption="DATA" I don't want repeat code many times for each sheet. if there is procedure to make code is short for each sheet will be great.
I want implement this code for four sheets based on select option buttons . the optionbuttons' name are the same sheets names . so any match name for the optionbuttion is same tfor each sheet name should copy data to spicific sheet is matched with optionbutton . optionbutton1.caption="PURCHASE",optionbutton2.caption="SALES" ,optionbutton3.caption="STOCK",optionbutton4.caption="DATA" I don't want repeat code many times for each sheet. if there is procedure to make code is short for each sheet will be great.
VBA Code:
Private Sub CommandButton4_Click()
Dim i As Long
With Sheets("PURCHASE")
.Range("e5").MergeArea = Me.TextBox1.Value
.Range("e8").MergeArea = Me.TextBox2.Value
For i = 1 To 11
.Cells(i + 1, 1).Value = Me.Controls("TextBox" & i)
Next i
For i = 12 To 44
.Cells(((i - 11) Mod 11) + 1, Int((i - 11) / 11) + 6).Value = Me.Controls("Textbox" & i)
Next i
For i = 2 To 45
.Cells(((i - 1) Mod 11) + 1, Int((i - 1) / 11) + 2).Value = Me.Controls("ComboBox" & i)
Next i
End With
TextBox34.Value = Me.TextBox12.Value * Me.TextBox23.Value
TextBox35.Value = Me.TextBox13.Value * Me.TextBox24.Value
TextBox36.Value = Me.TextBox14.Value * Me.TextBox25.Value
End Sub