Dynamic Price Box linked to ComboBox selection

Dtex20

Board Regular
Joined
Jan 29, 2018
Messages
50
Code:
Private Sub MachineOptionsBox_Change()
 
Dim priceCell As Range
Dim imprCell As Range
Dim selcItem As Long
Dim sRowN As Integer
Dim sCol As Integer
Dim ws As Worksheet
 
 
Set ws = Sheets("*Sheet Name*")
sRowN = 0
 
For Each priceCell In ws.Range("C1:C5000")
   If priceCell.Value = "Agents View" Then
   For selcItem = 0 To Me.MachineOptionsBox.ListCount - 1
     If priceCell.Offset(, -2).Value = MachineTypeBox.Value Then
         If priceCell.Offset(, 3).Value = CLng(Me.MachineOptionsBox.Selected(selcItem)) Then
           sRowN = priceCell.Row
          Exit For
          End If
     End If
   Next selcItem
   End If
   If sRowN > 0 Then
     Exit For
   End If
Next priceCell
 
 
For Each imprCell In ws.Range("BF4:BY4")
   If imprCell.Value = CLng(NoOfImpressionsBox.Value) Then
     sCol = imprCell.Column
     Me.AgentCostBox.Value = Me.AgentCostBox.Value + Cells(sRowN, sCol).Value
   End If
Next imprCell
 
AgentCostBox = Format(AgentCostBox, "£#,##0.00")

Hi guys,

I've got the basics of this code, it's a bit buggy at the moment. I'm trying to make so that when a item is selected it searching for the price via the numerous if and for each statements, and adds it to the CostBox.

When deselected it takes it away from the cost box, the current problems i'm having is trying to go through the combo box and match the cell value in offset 3. Also another problem i am having is that i do not know how to dynamically add to the price box, i can always add but never take away when selected. I imagine i need some sort of 'While' statement?

This may be hard to understand without and example, please let me know if you need more information.

Thanks,
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

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