Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Mona Mehta   on Feb 10 In MS Office Category.

  
Question Answered By: Muriel Dunn   on Feb 10

Again, this is not difficult. Do as follows:

1. Setup the "Price" column in worksheet (sheet1), with "Price" in
cell(C1), and the price of each product  starting from cell(C2) going
downwards. Fill all cells with prices, without any blank cells.

2. Add a new textbox (txtPrice) to form.

3. Add the following NEW code:


'-----------------------------------------------------------------

Private Sub lstProducts_Change()
Dim strSelectedProduct As String
Dim rngProducts As Range, rngDummy As Range

' Get the name of the selected  product
strSelectedProduct = lstProducts.Column(0, lstProducts.ListIndex)

' Identify the range of product cells
With ThisWorkbook.Worksheets("Sheet1")
Set rngProducts = .Range(.Range("B2"), .Range("B2").End
(xlDown))
End With

' Show the price of the selected product
For Each rngDummy In rngProducts
If rngDummy = strSelectedProduct Then
txtPrice = rngDummy.Offset(0, 1)
Exit For
End If
Next rngDummy
End Sub

'-----------------------------------------------------------------

Also, add the following pieces of code in the previously-created
event procedures:

Private Sub lstCategory_Change()
' OLD CODE
' OLD CODE
' OLD CODE

' Clear the txtPrice textbox
txtPrice = ""
End Sub


Private Sub UserForm_Activate()
' OLD CODE
' OLD CODE
' OLD CODE

' Lock the txtPrice textbox
txtPrice.Locked = True
End Sub


'-----------------------------------------------------------------

When you select  a product from lstProducts listbox, the selected
string is compared against the "Products" column in worksheet, until
a match is found, and the price value is written into the txtPrice
LOCKED textbox.

Share: 

 

This Question has 7 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Synchronize two combo boxes on a user form Or get search suggestion and latest updates.


Tagged: