Help with VBA

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi All
I need an automated method of replacing a formula when a change in a specific cell is made. I have been using a VBA method of double clicking in a cell to replace a formula. I have many layouts like this that consist of 12 rows. The next layout would be 14 thru 25. Column A and B are Index,Match formulas.
Sometimes column B needs to be overwritten. Lets say B5 is overwritten.
Sometimes the truck # might change. If it does, I need B5:B12 to update but B5 has no formula. I would then double click in B5 and the formula would be replaced. This is fast but it's not fail safe.
Is it possible to have the formulas in B5:B12 replaced with VBA when A2 changes? And the repeat for each layout.

B5 Formula: =IFERROR(INDEX('Patch By UNIVERSE'!$BH$3:$BH$5000,MATCH(AY5,'Patch By UNIVERSE'!$BG$3:$BG$5000,0)),"")

This would be awesome!

Thank you!

A
2Truck 1


AB
4LabelItem
5Crate 1Apple
6Crate 2Orange
7
8
19
10
11
12
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this in the sheet code module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$2" Then Exit Sub
Application.EnableEvents = False
Range("B5:B12").Formula = "=IFERROR(INDEX('Patch By UNIVERSE'!$BH$3:$BH$5000,MATCH(AY5,'Patch By UNIVERSE'!$BG$3:$BG$5000,0)),"""")"
Application.EnableEvents = True
End Sub
 
Upvote 0
Hey Whiz
That works exactly how I explained it!
1 thing that I didn't think to mention was that a change in A2 is the result from a formula.
Any tricks to make that work?
Thank you for getting me this far!
 
Upvote 0
=IFERROR(INDEX(CableBuild!AX$3:AX$1000,MATCH('Truss Snakes'!$BU2,'Multi Build'!CW$3:CW$1000,0)),"Location")
 
Upvote 0
You can try this, but it will run whether the change is in A2 or sormewhere else that generates a calculation. Maybe that would not matter.

Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Range("B5:B12").Formula = "=IFERROR(INDEX('Patch By UNIVERSE'!$BH$3:$BH$5000,MATCH(AY5,'Patch By UNIVERSE'!$BG$3:$BG$5000,0)),"""")"
Application.EnableEvents = True
End Sub
 
Upvote 0
You can try this, but it will run whether the change is in A2 or sormewhere else that generates a calculation. Maybe that would not matter.

Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Range("B5:B12").Formula = "=IFERROR(INDEX('Patch By UNIVERSE'!$BH$3:$BH$5000,MATCH(AY5,'Patch By UNIVERSE'!$BG$3:$BG$5000,0)),"""")"
Application.EnableEvents = True
End Sub
That would matter. I have an idea that might work if your interested in helping me.
 
Upvote 0
Well, if the changes that cause A2 to change are occuring in column W of another sheet, Maybe you need the change macro on that sheet instead of the one with the A2 value.
 
Upvote 0
Well, if the changes that cause A2 to change are occuring in column W of another sheet, Maybe you need the change macro on that sheet instead of the one with the A2 value.
That's why I asked for the formula of course, but that formula indicated that cells on three different sheets could cause A2 to change. Building Worksheet_Change events into all three sheets to do this task is not ideal so I would stick with the Calculate event so long as it is not slowing the sheet too much.
 
Upvote 0
The problem with using calculate is that it can change some manual entries to formulas prematurely because almost any change will trigger the calculate event. I cannot think of a way to confine the event to just certain columns on specific sheets.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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