Hi,
I have a userform where the operator is to select a choice from the Tankcbo and then there is a change event macro which is to update the Total, I am having a problem if the operator changed the selection where the total does not get updated, during tests it seems to be lagging one selection behind. I put a message box in to check the contents of the Total is empty which it is and then when I press ok the new total appears correctly, but when I take out the message box it goes back to displaying the previous result, any suggestions?
Regards,
I have a userform where the operator is to select a choice from the Tankcbo and then there is a change event macro which is to update the Total, I am having a problem if the operator changed the selection where the total does not get updated, during tests it seems to be lagging one selection behind. I put a message box in to check the contents of the Total is empty which it is and then when I press ok the new total appears correctly, but when I take out the message box it goes back to displaying the previous result, any suggestions?
Regards,
Rich (BB code):
Private Sub Tankcbo_Change()
Dim c As Range
Dim d As Long
Dim x As Range
Dim wbk As Workbook
Dim wsfrom As Worksheet
Set wbk = ThisWorkbook
Set wsfrom = wbk.Sheets("Data")
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Me.Total = ""
With wsfrom
Set rng = .Range(.Range("II7"), .Range("II" & .Rows.count).End(xlUp))
For Each c In rng
If c.Value = Me.McNo.Text And c.Offset(, 1) = Me.WON.Text And c.Offset(, 12).Text = Me.FlavNo.Text Then
d = c.Row
Me.Total = ""
With wsfrom
.Cells(d, 260).Value = ""
.Cells(d, 260).Value = Me.Tankcbo.Text
End With
Me.Total = ""
MsgBox Me.Total.Value
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
With wsfrom
If c.Offset(, 7).Text = "Natural" Then
Me.Total = Format(c.Offset(, 27).Value, "0")
Else
Me.Total = c.Offset(, 27).Value
End If
End With
End If
Next c
Me.Row = d
Me.TankNo.SetFocus
End With
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub