abdo meghari
Well-known Member
- Joined
- Aug 3, 2021
- Messages
- 573
- Office Version
- 2019
Hi guys !
I need modifying this code by copy to the bottom instead of replacing with old data .
the code contains group of textboxes and comboboxes and copy to sheet based on selection option button from column A:H but the problem replacing with old data , should copy to the bottom when every time press commandbutton4
I hope somebody help
I need modifying this code by copy to the bottom instead of replacing with old data .
the code contains group of textboxes and comboboxes and copy to sheet based on selection option button from column A:H but the problem replacing with old data , should copy to the bottom when every time press commandbutton4
VBA Code:
Private Sub CommandButton4_Click()
Dim i As Long
Dim sheetname As String
For i = 1 To 4
With Me.Controls("OptionButton" & i)
If .Value Then sheetname = .Caption: Exit For
End With
Next i
With Worksheets(sheetname)
.Range("e5").MergeArea = Me.TextBox1.Value
.Range("e8").MergeArea = Me.TextBox2.Value
For i = 1 To 11 'This is unmodified
'' Debug.Print "TextBox_" & i, Cells(i + 1, 1).Address(0, 0)
.Cells(i + 1, 1).Value = Me.Controls("TextBox" & i)
Next i
For i = 12 To 44
'' Debug.Print "TextBox_" & i, Range("F2").Offset((i - 12) Mod 11, Int((i - 12) / 11)).Address(0, 0)
.Range("F2").Offset((i - 12) Mod 11, Int((i - 12) / 11)).Value = Me.Controls("Textbox" & i)
Next i
For i = 2 To 45
'' Debug.Print "ComboBox_" & i, Range("B2").Offset((i - 2) Mod 11, Int((i - 2) / 11)).Address(0, 0)
.Range("B2").Offset((i - 2) Mod 11, Int((i - 2) / 11)).Value = Me.Controls("ComboBox" & i)
Next i
End With
TextBox16.Value = Me.TextBox8.Value * Me.TextBox12.Value
TextBox17.Value = Me.TextBox9.Value * Me.TextBox13.Value
TextBox18.Value = Me.TextBox10.Value * Me.TextBox14.Value
TextBox34.Value = Me.TextBox12.Value * Me.TextBox23.Value
End Sub