Hello everyone,
I have a list box in which you can select multiple items. When you click modify, it will analyze which items are selected and go through all of them.
That means it will first display the first Item with the Item ID and other information from the same line.
Then I have the option to click update ID which works fine. However I do not update the ID in the listbox.
Now I click Update Price and it doesn't work because now its trying to match the previously changed ID to the ID's that are in the listbox.
I cannot change the position of the item in the list (i.e. remove and then add an item) because I use the position within the list as reference.
I want to know how I can just update the item in the list with the new ID.
Maybe something like GUI.lstBonds.Selected = Price ?!
ModifyBondPosition is a public Variable
I have the following code:
Does anyone know a way to modify/update one list item?
I have a list box in which you can select multiple items. When you click modify, it will analyze which items are selected and go through all of them.
That means it will first display the first Item with the Item ID and other information from the same line.
Then I have the option to click update ID which works fine. However I do not update the ID in the listbox.
Now I click Update Price and it doesn't work because now its trying to match the previously changed ID to the ID's that are in the listbox.
I cannot change the position of the item in the list (i.e. remove and then add an item) because I use the position within the list as reference.
I want to know how I can just update the item in the list with the new ID.
Maybe something like GUI.lstBonds.Selected = Price ?!
ModifyBondPosition is a public Variable
I have the following code:
Rich (BB code):
Public Sub btnModifyBond_Click()
Call ModifySelectedBonds
End Sub
Rich (BB code):
Public Sub ModifySelectedBonds()
For ModifyBondPosition = 0 To GUI.lstBonds.ListCount - 1
If GUI.lstBonds.Selected(<wbr style="font-family: arial, sans-serif;">ModifyBondPosition) = True Then
UserFormModifyBond.Show
End If
Next ModifyBondPosition
MsgBox "No more bonds selected"
End
End Sub
Rich (BB code):
Public Sub UserForm_Activate()
'Name BondID Range
Worksheets("Bonds").Activate
Worksheets("Bonds").Range("B:<wbr style="font-family: arial, sans-serif;">B").Name = "BondIDs"
'Put Previous Values in Textboxes
Dim y As String
y = GUI.lstBonds.List(<wbr style="font-family: arial, sans-serif;">ModifyBondPosition)
s = Application.Match(y, Range("BondIDs"), 0)
txtModifyID.Text = Worksheets("Bonds").Cells(s, 2).Value
txtModifyPrice.Value = Worksheets("Bonds").Cells(s, 4).Value
txtModifyPrice.Value = Format(txtModifyPrice.Value, "#,##0.00")
txtModifyMaturity.Text = Worksheets("Bonds").Cells(s, 3).Value
txtModifyCoupon.Text = Worksheets("Bonds").Cells(s, 5).Value
txtModifyCoupon.Text = Format(txtModifyCoupon.Text * 100, "0.00")
txtModifyFaceValue.Text = Worksheets("Bonds").Cells(s, 6).Value
txtModifyFaceValue.Value = Format(txtModifyFaceValue.<wbr style="font-family: arial, sans-serif;">Value, "#,##0.00")
End Sub
Rich (BB code):
Private Sub btnUpdateID_Click()
'Error Message if Input is missing
If txtModifyID.Value = "" Then
MsgBox "ID is missing"
txtModifyID.SetFocus
Exit Sub
End If
Dim BondID As String
BondID = txtModifyID.Value
'Test if Input is unique
For r = 2 To WorksheetFunction.CountA(<wbr style="font-family: arial, sans-serif;">Range("B:B")) - 1
Dim PreviousID As String
PreviousID = Cells(r, 2)
If BondID = PreviousID Then
MsgBox "Unfortunately, this Bond ID already taken. Please enter a different BondID."
txtModifyID.SetFocus
Exit Sub
End If
Next r
'Name BondID Range
Worksheets("Bonds").Activate
Worksheets("Bonds").Range("B:<wbr style="font-family: arial, sans-serif;">B").Name = "BondIDs"
'Update ID
Dim a As String
a = GUI.lstBonds.List(<wbr style="font-family: arial, sans-serif;">ModifyBondPosition)
b = Application.Match(a, Range("BondIDs"), 0)
Cells(b, 2) = BondID
'Update List here?!
End Sub
Rich (BB code):
Private Sub btnUpdatePrice_Click()
'Error Message if Input is missing
If txtModifyPrice.Value = "" Then
MsgBox "Price is missing"
txtModifyPrice.SetFocus
Exit Sub
End If
Dim Price As String
Price = txtModifyPrice.Value
'Test if Inputs is Numeric
If Not IsNumeric(txtModifyPrice.<wbr style="font-family: arial, sans-serif;">Value) Then
MsgBox "Price has to be a number"
txtModifyPrice.SetFocus
Exit Sub
Else
Price = Format(txtModifyPrice.Value, 0#)
End If
'Name BondID Range
Worksheets("Bonds").Activate
Worksheets("Bonds").Range("B:<wbr style="font-family: arial, sans-serif;">B").Name = "BondIDs"
'Update Price
Dim a As String
a = GUI.lstBonds.List(<wbr style="font-family: arial, sans-serif;">ModifyBondPosition) 'a is now the ID from the listbox (i.e. the previous ID)
b = Application.Match(a, Range("BondIDs"), 0) 'VBA can't find a row for b since the ID in the list is not in the cell anymore
Cells(b, 4) = Price
End Sub
Does anyone know a way to modify/update one list item?