How to keep Formulas in excel from moving with columns when inserting.

BenGrobler

New Member
Joined
Apr 19, 2021
Messages
31
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a formula that starts in Column"O" , each time i process data that is captured in Column "O" then a new column is inserted for the next data.
My Formula is =COUNTIF(O4:XFD4,"Cool") after inserting the new column my formula is =COUNTIF(P4:XFD4,"Cool")

i need it to stay the same after inserting a new column?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Where exactly are these new columns being inserted?
Are you sure that is how it is updating the formula? It seems odd that it is updating the starting the cell (O4), but not the ending cell (XFD4). Usually, both would be updated if you insert a nwe column.

It may be helpful to see a small data sample.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Where exactly are these new columns being inserted?
Are you sure that is how it is updating the formula? It seems odd that it is updating the starting the cell (O4), but not the ending cell (XFD4). Usually, both would be updated if you insert a nwe column.

It may be helpful to see a small data sample.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Attendance List Trends.xlsm
ABCDEFGHIJKLMNOPQRSTU
1SA Metal ELF Employees00 January 1900
2COY NumberEmployee Name & SurnameAwopSickLateAnnual LeaveFam Resp LeaveLong Service LeaveUnpaid LeaveWCASuspendedDismissedResigned
3
4902Andries Sibiya00000000000
5903Frans Bila 00000000000
6909Mario Machava00000000000
7910Kheti Kanye00000000000
8913Jaime Mausse00000000000
9916Jeremiah Nkosi 00000000000
10952Bongi Shelembe00000000000
11954Mxosheni Nsibande00000000000
122507Life Khubayi00000000000
132806Moleke Malepe00000000000
Trend
Cell Formulas
RangeFormula
O1O1='SAM ELF YARD ATTENDENCE'!M2
C4:C13C4=COUNTIF(P4:XFD4,"AWOP")
D4:D13D4=COUNTIF(P4:XFD4,"Sick")
E4:E13E4=COUNTIF(P4:XFD4,"Late")
F4:F13F4=COUNTIF(P4:XFD4,"Annual Leave")
G4:G13G4=COUNTIF(P4:XFD4,"Fam Resp Leave")
H4:H13H4=COUNTIF(P4:XFD4,"Long Service Leave")
I4:I13I4=COUNTIF(P4:XFD4,"Unpaid Leave")
J4:J13J4=COUNTIF(P4:XFD4,"WCA")
K4:K13K4=COUNTIF(P4:XFD4,"Suspended")
L4:L13L4=COUNTIF(P4:XFD4,"Dismissed")
M4:M13M4=COUNTIF(P4:XFD4,"Resigned")
 
Upvote 0
Thanks for posting a data sample, but you did not answer either question that I asked.
 
Upvote 0
It looks like you could just start your formula at column N, since it's blank, then inserting new columns before column O won't be a problem.
 
Upvote 0
Thanks for posting a data sample, but you did not answer either question that I ask
the data is entered in column N and a new column is inserted. N becomes O, the formulas start in O
 
Upvote 0
One trick would be to insert a blank column at column N, then hide it, and use that as the start column in your COUNTIF formulas.
Then insert all new columns starting at column O.
 
Upvote 0
It looks like you could just start your formula at column N, since it's blank, then inserting new columns before column O won't be a problem.
that does not work when the new column is inserted the formula then starts with O, insert again and the formula starts with P
 
Upvote 0
I need the formula to reset itself back to column O or N with a vba code or something? Any Idea?
 
Upvote 0
that does not work when the new column is inserted the formula then starts with O, insert again and the formula starts with P
You hadn't mentioned that the inserting was happening at the column I suggested using as the anchor. I'd add a blank separator column and hide it. Then use that as the anchor.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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