Hello Beautiful people,
Pls i am new to excel vba . i have a problem with a project i am creating.
I have list of items(Tanks) in a listbox. Anytime i select an item(tank) and Add, the the userform unloads and the listbox selection also unloads.
i don't want to keep on choosing a tank after the userform unloads
i want the selected tank to remain even if the userform unloads. Below is the code .
Pls i am new to excel vba . i have a problem with a project i am creating.
I have list of items(Tanks) in a listbox. Anytime i select an item(tank) and Add, the the userform unloads and the listbox selection also unloads.
i don't want to keep on choosing a tank after the userform unloads
i want the selected tank to remain even if the userform unloads. Below is the code .
VBA Code:
Private Sub lstTankName_Click()
On Error Resume Next
cmdAdd.Enabled = True
lblDate.Visible = False
lblTransuctionID.Visible = False
txtQuantity.Value = ""
txtKG.Value = ""
For x = 0 To lstTankName.ListCount - 1
lblTankCode.Caption = lstTankName.List(lstTankName.ListIndex, 0)
lblTkName.Caption = lstTankName.List(lstTankName.ListIndex, 1)
If lstTankName.Value = 1 Then
Unload lstTankName
lstTankName.ListIndex = 1
End If
Next x
If Sheet2.Range("B:B") = UserForm1.lblTankCode Then
m = Application.WorksheetFunction.SumIf(Sheet2.Range("B:B"), UserForm1.lblTankCode, Sheet2.Range("D:D"))
n = Application.WorksheetFunction.SumIf(Sheet3.Range("B:B"), UserForm1.lblTankCode, Sheet3.Range("D:D"))
p = n - m
lblStock.Caption = p
End If
End Sub