Formula not calculating after VBA. Need to click each cell

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello,

I used
screenupdating = false
Application.Calculation = xlCalculationManual

Because code was working very slow. Now it works very fast but not calculating cells. I need to click each cell to calculate result.
Any solution please? I tried replace "=" with "=" but still no luck..

VBA Code:
Option Explicit

Sub Sample()
    
    Dim ws As Worksheet
    Dim ColName As String
    Dim ColNumber As Long
    Dim i As Long
    Dim CpyFrom As range
    Dim Cell As range
    Dim ColCounter As Integer
    Dim LR As Long
    
    
    'Turn of screenupdating to improve performance
    'Dim savedScreenUpdating As Boolean
    'savedScreenUpdating = Application.ScreenUpdating
    Application.ScreenUpdating = False
    
    
    'Make Excel calculation manual to improve performance
    'Dim savedCalcMode As XlCalculation
    'savedCalcMode = Application.Calculation
    Application.Calculation = xlCalculationManual
    
    '~~> Sheet name to format
    Set ws = Sheets("DATA TO FORMAT (2)")
    ColCounter = 1

    'for each rows
    Set CpyFrom = ws.range("L10003:L10542")
    
    ColName = ws.range("B9").Value2
    ColNumber = range(ColName & 1).Column
    
    '~~> Here is the loop from 0 to col number
    For i = 0 To ColNumber - 13
    
     For Each Cell In CpyFrom
        If Cell.Value <> vbNullString Then
            Cell.Offset(0, i + 1).Value = Cell.Offset(0, 1).Formula2R1C1
        End If
    Next Cell
    Next i
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    

    range(Cells(10003, 12), Cells(10542, Rows("10003:10542").Find("*", , xlFormulas, , 2, 2).Column)).Replace "=", "="
    
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try putting the:

VBA Code:
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

right before 'End Sub'

In other words, move it down past the:
VBA Code:
    range(Cells(10003, 12), Cells(10542, Rows("10003:10542").Find("*", , xlFormulas, , 2, 2).Column)).Replace "=", "="
 
Upvote 0
Thanks for reply. But still no luck.. result is same
Btw I changed this line
VBA Code:
Cell.Offset(0, i + 1).Value = Cell.Offset(0, 1).Formula2R1C1
to this also
Code:
Cell.Offset(0, i + 1).Formula = Cell.Offset(0, 1).Formula
 
Last edited:
Upvote 0
Well if you turned stuff off, turned it back on, I am not sure what you are asking for. Can you provide some more info?
 
Upvote 0
All cells are blank, not showing any result. But when I click in formula and click enter it returns result.
I tried to calculate with VBA
Also clicked "Calculate now"
Still results are blank. It returns results only when I click on formula and press enter.
 
Upvote 0
One more think I just tested.
When I replace "=" with "-" it works.
Then I tried replace again "-" to "=" it does not works. so I guess problem is in replacement line?
Edit: it doesn't works because it is not formula anymore. So problem is not this.
 
Last edited:
Upvote 0
What formula do you have in M10003 ?
Also in N10003 what is the format in the format box, is it General or something else ?
 
Upvote 0
M is number
N is general
Formula:
VBA Code:
=IFERROR(IF(M$10001="AVERAGE",SUMIF(INDIRECT($B10003&"$11:"&$B10003&$C$9),">"&"0",INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1","$11")&":"&SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1",$C$9)))/IF(ISNUMBER(SEARCH("_DO_",M$1)),"",SUMPRODUCT(--(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1","$11")&":"&SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1",$C$9))<>""),(INDIRECT($B10003&"$11:"&$B10003&$C$9)))),IF(M$10001="COUNT",COUNTIFS(INDIRECT($B10003&11&":"&$B10003&$C$9),">="&"1",INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","11")&":"&SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1",$C$9)),"<="&"3"),IF(ISNUMBER(SEARCH("_DO_",M$1)),"",SUMPRODUCT(--(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1",11)&":"&SUBSTITUTE(ADDRESS(1,COLUMN(M11),4),"1",$C$9))<>""),(INDIRECT($B10003&"$11:"&$B10003&$C$9)))))),"")
 
Upvote 0
Ouch. I would need a copy of your spreadsheet to replicate that.

If I put a simple formula in M10003 your most recent code works fine for me:
VBA Code:
Cell.Offset(0, i + 1).Formula = Cell.Offset(0, 1).Formula

In relation to your speed issues you don't need 2 loops.
In theory should also not need that final replace but unless the below accidentally fixes the issue we still need to find a fix for that.
If the issue persists after the below can you just try changing Formula on both sides to Formula2 to see if it makes a difference ?

Rich (BB code):
    '~~> Here is the loop from 0 to col number
    'For i = 0 To ColNumber - 13
        For Each Cell In CpyFrom
            If Cell.Value <> vbNullString Then
                'Cell.Offset(0, i + 1).Formula = Cell.Offset(0, 1).Formula
                Cell.Offset(0, 2).Resize(1, ColNumber - 13).Formula = Cell.Offset(0, 1).Formula
            End If
        Next Cell
    'Next i
 
Last edited:
Upvote 0
Solution
Thank you so much.. I just commented last line ( replacement )
Now it works..
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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