fixing error type mismatch ( after copy data from userform to sheet)

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
hi
I got some help from Mr.Fluff to copy data from userform contains many multiple textboxes & comboboxes by using loop
Code:
Private Sub CommandButton1_Click()
   Dim i As Long
  
   With Sheets("Invoice")
      .Range("e5").MergeArea = Me.TextBox1.Value
      .Range("e8").MergeArea = Me.TextBox2.Value

      For i = 3 To 6
         .Cells(i + 13, 1).Value = Me.Controls("TextBox" & i)
      Next i
      For i = 7 To 18
         .Cells(((i - 7) Mod 4) + 16, Int((i - 7) / 4) + 5).Value = Me.Controls("Textbox" & i)
      Next i
      For i = 1 To 12
         .Cells(((i - 1) Mod 4) + 16, Int((i - 1) / 4) + 2).Value = Me.Controls("ComboBox" & i)
      Next i
   End With
   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
. the problem is after copy data from userform to sheet in this part of code
VBA Code:
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
this problem shows error mismatch when some textboxes are empty . so it should copy without any problem even some textboxes are empty
thanks in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,
try using the VAL function to coerce your text to numeric value. If nothing is entered, Val returns 0 (zero)

VBA Code:
   TextBox15.Value = Val(Me.TextBox7.Value) * Val(Me.TextBox11.Value)
   TextBox16.Value = Val(Me.TextBox8.Value) * Val(Me.TextBox12.Value)
   TextBox17.Value = Val(Me.TextBox9.Value) * Val(Me.TextBox13.Value)
   TextBox18.Value = Val(Me.TextBox10.Value) * Val(Me.TextBox14.Value)

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

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
Back
Top