Excel VBA Worksheet_Change

MaxMiller

New Member
Joined
Apr 6, 2011
Messages
11
I am trying to automatically change values by a percentage when they are entered based on criteria contained in a previous row.

moz-screenshot.png
I have tried to do this using the following code:

Public Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("I14:I44")) Is Nothing Then
With Target
If IsNumeric(.Value) Then
.Value = .Value * 1.08
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Problem is I want to calculate a different percentage based on the values of "E14:E44" which are bound by the following list: "LTL", "Truckload", "Tank Truck" & "IM". I think some sort of Vlookup would be ideal but not sure if that can be incorporated into Worksheet_change.

Any help is greatly appreciated!
 
You can only declare a same-named variable once in the same macro or procedure. So delete it out of each of the 2 places where you have it now, and for simplicity's sake, have that statement, which is
Dim pctVal As Double
be the very first statement in the SheetChange event, directly below and after
Public Sub Worksheet_Change(ByVal Target As Range)
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I am having trouble with modifying the code to expand the functionality to column J & K.

If Intersect(Target, Range("I14:I44")) Is Nothing _
Or Target.Cells.Count > 1 Then Exit Sub
If IsEmpty(Target) = True Then Exit Sub
</pre>The code is triggering exiting the sub before I can get the to the next range... is there some sort of if then go to next if statement instead of exit sub?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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