Help to auto extend formula when new column is added daily

vkingxl

New Member
Joined
Feb 2, 2020
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
I have a sheet called "A-LOG" and every day I use an excel VBA macro to take a snapshot of column A which has live alarm data, and pastes a copy of column A after the last column on the sheet with data in it. Over time I have a good indicator of daily alarms history. I also use a simple formula in column B to count how many alarms are found across each row's range of columns.
Existing formula: =COUNTIF(B4:BZJ4,"?*")

The problem is every few months or so I need to keep manually changing the last column text to expand the formula. I have the following VBA in my macro to find the last column in use and I added the bold text to now also paste that numeric value into the A-LOG sheet.

LastColumn = Sheets("A-LOG").Cells(1, Sheets("A-LOG").Columns.Count).End(xlToLeft).Column
Sheets("A-LOG").Range("Z1") = LastColumn

Then I found this formula that converts that numeric value into the text column name equivalent so I put that in Z2
Z2
=SUBSTITUTE(ADDRESS(1, Z1, 4), "1", "")

Then I was thinking I could use INDIRECT to use in my count formula like:
=COUNTIF(B4:INDIRECT(Z$2&4),"?*")
Which does supply the correct count, but I can't copy this formula down the page as the 4 number doesn't change.

Maybe there is a more efficient solution or formula that could be used, but I do have about 15k rows so I do want to be mindful of calculation stress on the workbook.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If the formula is in col B, how about
Excel Formula:
=COUNTIFS(C4:INDEX(4:4,,$Z$1),"?*")
 
Upvote 0
You do have a large calculation range so the calculation is fairly onerous. However, my test worksheet (15,000 rows x 2,000+ columns) shows no extra calculation time for a countifs formula if you simply use the full available range without worrying about Z1:Z2
Excel Formula:
=COUNTIFS(C4:XFD4,"?*")

And without knowing what your data is actually like, would this do the same job as it is considerably faster with my test data?
Excel Formula:
=COUNTA(C4:XFD4)
 
Upvote 0
Solution
Awesome - all 3 of those answers solved my question. I also was working with this answer when your responses came through.
=COUNTA(A4:INDEX(4:4, 1, Z$1))

Since the =COUNTA(C4:XFD4) is so simple and fast I would have used that one, but I did have another calculation in another column counting back 15 days to show how many times the unit was alarmed. So knowing the last column # in Z1 is most beneficial in my case.

Thank you both very much!!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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