Auto calculate based on column value

looney

New Member
Joined
Mar 4, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All,

So I have this code to multiply entries made in J9:L9 by the value in the same column cell 4.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Application.Intersect(Target, Range("J9:L38")) Is Nothing Then Exit Sub
If Target.CountLarge <> 1 Then Exit Sub
On Error GoTo catch

Application.EnableEvents = False
Target.Value = Target.Value * Cells(4, Target.Column)

catch:
Application.EnableEvents = True

End Sub

I want to change this so that entires would instead multiply by whatever is in column K, but keeping a relative cell reference, for example:

Enter a value in J9 and the result will be J9*K9
Enter a value in J9 and the result will be J10*K10
Enter a value in J9 and the result will be L9*K9
Enter a value in J9 and the result will be L10*K10

A great bonus to have would be a message box that would run asking the user to fill column K first, if they try to enter a value in the range J9:L38, but K is empty.

Thank you in advance!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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