VBA Macro

T

Thomas Price

I am trying to get cell (S5) to auto fill when you enter the weight of the
vehicle in cell (W5). If the vehicle weights 50,000 lbs or more it needs to
be classified as a "HEAVY TRUCK". If the weight is less than 50,000 it needs
to be classified as a "LT DUTY TRUCK". If there is no weight filled in I
want to manually enter the classification. My VBA macro I pasted into the
sheet is not working. Can anyone help me fix this? Thanks!

Here is what I have so far

Private Sub Worksheet_Change1(ByVal Target As Range)
If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = 0 Then
Exit Sub
End If
If Target.Value >= 50000 Then
Range("S5").Value = "HEAVY TRUCK"
End If
If Target.Value < 50000 Then
Range("S5").Value = "LT DUTY TRUCK"
End If
Application.EnableEvents = True
End Sub
 
O

Office_Novice

Change Cell Ranges to what you want and you should be good to go.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("A5"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = 0 Then
Exit Sub
End If
If Target.Value >= 50000 Then
Range("C5").Value = "HEAVY TRUCK"
End If
If Target.Value < 50000 Then
Range("C5").Value = "LT DUTY TRUCK"
End If
Application.EnableEvents = True
End Sub
 
T

Thomas Price

Thanks! I am running into one problem. I have a macro before this one and
that is what seems to be the problem. I know that each one works seperatly
but I don't know how to get them both to work. This is what I have.

Private Sub Worksheet_Change1(ByVal Target As Excel.Range)
If Not Application.Intersect(Range("j:k", "y:y"), Target) Is Nothing Then
On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Formula = UCase(Target.Formula)
End If
ErrHandler:
Application.EnableEvents = True
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("W5"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = 0 Then
Exit Sub
End If
If Target.Value >= 50000 Then
Range("S5").Value = "HEAVY TRUCK"
End If
If Target.Value < 50000 Then
Range("S5").Value = "LT DUTY TRUCK"
End If
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top