Formula keeps changing

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, I have a puzzle that I cannot solve,
I have the following formula to count the number of nonblank cells in a column
="Check Type "&COUNTIF($AA$2:$AA$7500,"<>")
The spreadsheet is refreshed daily and I use thefollowing code to clear out the dataprior to the refresh.
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If
Range("A2:Ay50000").Cells.Clear

However after the code has fully run and I check the aboutformula it has reduced the number of rows it is looking at.
="Check Type "&COUNTIF($AA$2:$AA$7497,"<>")
As I am using $$ I did not think the formula can change.
Am I being silly?

 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello,

The $ refers to an absolute reference, so that when you copy the formula across it won't change - 1 reason why it's going from 7500 down to 7497 could be that 3 rows are being deleted between 2 and 7500.
 
Upvote 0
It's not clear where the fomulas are i.e. cell address. Try this to begin with:
Code:
Sub mTest1()

    Dim LR  As Long
    Dim LC  As Long
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlManual
    End With
    
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilterMode = False
        LR = .Cells(.Rows.Count, 1).End(xlUp).Row
        LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
        .Cells(2, 1).Resize(LR - 1, LC).Value = ""
    End With
    
     With Application
        .ScreenUpdating = False
        .Calculation = xlManual
    End With
    
End Sub
I think .Cells.Clear "deletes" the cells entirely, whilst .Value = "" only chages the cell values. This could explain why your formula range changes.
 
Last edited:
Upvote 0
Bingo, at the end of the VBA it does delete unrequired rows, so rather than leave the formula in the cell, i just need to add it to the coding to count to last row. As it was part of the template i did not even consider the rows being deleted.

thanks
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,257
Members
448,952
Latest member
kjurney

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