Hi Everyone
I have a listbox in a user form that is populated using a dynamic array in a name manager which it is referencing.
The listbox has 2 columns.
First column is part number, second column is it's weight.
Now some part numbers do not have weights i.e. second column is empty.
I am trying to multiply the selected rows by a textbox value which I am then copying into another sheet using a command button.
However, if the text box is empty it won't run "Run Time 13 Error"
It also doesn't run when I try to multiply rows with empty second column values by the textbox value (if I input one in).
Basically I would like it to still copy over the first column via the command button regardless of when the second column has a value or the text box has a value. Preferably I would like the second column to be just Null if this is the case.
Can you please let me knowhow to do this Below is my code?
I have a listbox in a user form that is populated using a dynamic array in a name manager which it is referencing.
The listbox has 2 columns.
First column is part number, second column is it's weight.
Now some part numbers do not have weights i.e. second column is empty.
I am trying to multiply the selected rows by a textbox value which I am then copying into another sheet using a command button.
However, if the text box is empty it won't run "Run Time 13 Error"
It also doesn't run when I try to multiply rows with empty second column values by the textbox value (if I input one in).
Basically I would like it to still copy over the first column via the command button regardless of when the second column has a value or the text box has a value. Preferably I would like the second column to be just Null if this is the case.
Can you please let me knowhow to do this Below is my code?
VBA Code:
Private Sub cmdAdd_Click()
Dim addme As Range, cNum As Integer
Dim x As Integer, y As Integer, Ck As Integer
'set variables
Set addme = Sheet2.Cells(Rows.Count, 4).End(xlUp).Offset(1, 0)
cNum = 3
Ck = 0
'run the for loop
For x = 0 To Me.lstMulti.ListCount - 1
'add condition statement
If Me.lstMulti.Selected(x) Then
Ck = 1
'second loop
For y = 0 To cNum
addme.Offset(0, y) = Me.lstMulti.List(x, y)
Next y
Sheet2.Cells(Rows.Count, 6).End(xlUp).Offset(1, 0) = Me.lstMulti.List(x, 1) * TextBox1.Value
Sheet2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0) = TextBox1.Value
Set addme = addme.Offset(1, 0)
End If
'clear the selected values
lstMulti.Selected(x) = False
Next x
'send a message if nothing is selected
If Ck = 0 Then
MsgBox "There is nothing selected"
End If
End Sub