Macro which changes the inside formula

PetarTen

New Member
Joined
Oct 3, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi Folks, a newbie here...
I made a Macro that Kenji did here:
It was fun building it until I ran into something annoying - every time after execution the Table would shift one row to the right, which CHANGED the Reference within the Formula (that I wrote in the nearby table)
Please look at the attached pic!
After the Run, the cell E3 has been moved to the right and changed to G3
Why is this happening, after I purposely "told" Excel, to LOCK that particular cell by typing $E$3 (you can see it)
What else do I need to change?
BTW, if you ask me, "Have you tried running the Macro with 'Relative Reference On/Off' - YES, I have!"
Please if anyone here knows how to work around this problem - I would greatly appreciate it! 🙏
 

Attachments

  • Screenshot (84900).png
    Screenshot (84900).png
    150.3 KB · Views: 16
If I am not mistaken, your formula is changing because of this:

VBA Code:
Sheets("Mix").Select
Selection.Insert Shift:=xlToRight

It doesn't matter if you use absolute cell reference to lock it, the formula will update the column/row when you insert cells or move the referenced cell.
So?
How to go around this ?I
Is it even possible?
I tried to change the name of the Cells in that particular Column.
For instance - I changed the name of the Column where the weight values appear to Table 2 ....and add a Total for all the weights in that column - well, there's no problem! :) It shows correctly 95 gr
After running Macro, the Total from Table2 is perfectly updated and the =SUM is normally updated, i.e. I see different value (check the screenshot)
But...when I try for a single Cell - it refuses to make it absolute ref :( (Cell E3 goes two Cells to the right)
 

Attachments

  • Screenshot (86030).png
    Screenshot (86030).png
    144.1 KB · Views: 5
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Did you save the file using a macro where you changed the file extension?
 
Upvote 0
Looking at your first post if you just want the formula to reference column E when you insert 2 columns try...
Excel Formula:
=(INDEX($E:$E,3)*A5)/100
 
Last edited:
Upvote 0
Looking at your first post if you just want the formula to reference column E when you insert 2 columns try...
Excel Formula:
=(INDEX($E:$E,3)*A5)/100
Sub Herb1()
'
' Herb1 Macro
'

'
Range("E23:G29").Select
Selection.Copy
Sheets("Sheet1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("B:B,C:C").Select
Range("C1").Activate
With Selection
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("B2:C8").Select
Selection.Copy
Sheets("Mix").Select
Range("D3").Select
Selection.Insert Shift:=xlToRight
Sheets("Kitchen").Select
Range("E5").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("E7").Select
Selection.ClearContents
Range("E9").Select
Selection.ClearContents
Range("E11").Select
Selection.ClearContents
Range("E13").Select
Selection.ClearContents
Range("E15").Select
Selection.ClearContents
Range("E17").Select
Selection.ClearContents
Range("G5").Select
Selection.ClearContents
Range("G7").Select
Selection.ClearContents
Range("G9").Select
Selection.ClearContents
Range("G11").Select
Selection.ClearContents
Range("G13").Select
Selection.ClearContents
Range("G15").Select
Selection.ClearContents
Range("G17").Select
Selection.ClearContents
End Sub
___________________________________

Тhis is the MACRO code, right?

Where exactly to insert:
=(INDEX($E:$E,3)*A5)/100
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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