make code is short (loop throught tools on userform)

abdo meghari

Board Regular
Joined
Aug 3, 2021
Messages
71
Office Version
  1. 2019
hi
i try making macro to copy data from userform to sheet with multiple textbox and combobox . it take from me more time if i have many combobox and textbox so i truly apprecitae if there is way to make the code is short
VBA Code:
Private Sub CommandButton1_Click()
Dim lr As Integer
Dim ws As Worksheet
Set ws = Sheets("invoice")
Range("e5").MergeArea = Me.TextBox1.Value
 Range("e8").MergeArea = Me.TextBox2.Value
Range("a16").Value = Me.TextBox3
Range("a17").Value = Me.TextBox4
Range("a18").Value = Me.TextBox5
Range("a19").Value = Me.TextBox6
Range("E16").Value = Me.TextBox7
Range("E17").Value = Me.TextBox8
Range("E18").Value = Me.TextBox9
Range("E19").Value = Me.TextBox10
Range("F16").Value = Me.TextBox11
Range("F17").Value = Me.TextBox12
Range("F18").Value = Me.TextBox13
Range("F19").Value = Me.TextBox14
Range("G16").Value = Me.TextBox15
Range("G17").Value = Me.TextBox16
Range("G18").Value = Me.TextBox17
Range("G19").Value = Me.TextBox18
Range("B16").Value = Me.ComboBox1
Range("B17").Value = Me.ComboBox2
Range("B18").Value = Me.ComboBox3
Range("B19").Value = Me.ComboBox4
Range("C16").Value = Me.ComboBox5
Range("C17").Value = Me.ComboBox6
Range("C18").Value = Me.ComboBox7
Range("C19").Value = Me.ComboBox8
Range("D16").Value = Me.ComboBox9
Range("D17").Value = Me.ComboBox10
Range("D18").Value = Me.ComboBox11
Range("D19").Value = Me.ComboBox12

TextBox15.Value = Me.TextBox7.Value * Me.TextBox11.Value
TextBox16.Value = Me.TextBox8.Value * Me.TextBox12.Value
TextBox17.Value = Me.TextBox9.Value * Me.TextBox13.Value
TextBox18.Value = Me.TextBox10.Value * Me.TextBox14.Value

End Sub
can anybody help ,please? if this is not enough I will attach picture for userform
thanks in advance
 

abdo meghari

Board Regular
Joined
Aug 3, 2021
Messages
71
Office Version
  1. 2019
believe me it doesn't deserve starting new thread .the problem is very simple and I fixed it by using this line
VBA Code:
 On Error Resume Next
any way thanks for your code . it helps me so much ;)
 

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)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
66,086
Office Version
  1. 365
Platform
  1. Windows
It is a totally different which is why it needed a new thread.
That line of code does NOT fix anything, it just ignores errors, which could cause major problems. You should NEVER just put that line of code on it's own in a procedure.
 

Forum statistics

Threads
1,148,424
Messages
5,746,597
Members
424,032
Latest member
pochie2741

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
Top