Avatar of leezac
leezac asked on

Formulas not refreshing second time button is clicked.

A button is clicked to refresh data.  It works the 1st time but not the second.  Is there anyone that can look at this code and tell me why it would refresh one time and not the other?  It seems to refresh when the sheet is first open and initiated but not the second time.

Dim iD As Integer, iK As Integer
Dim EKN As String

EKNFormula = False
Application.EnableEvents = True
iK = 1
Sheet1.Activate
If Sheet1.CommandButton3.Caption = "Refresh" Then
    iD = Range("J6").End(xlDown).Row
    EKN = "=RData(J6:J" & iD & ",K4,,," & iQt & "CH:Fd" & iQt & ",K5)"
    Sheet1.Range("J4").Formula = EKN
    iD = iRefresh
    Sheet1.CommandButton3.Caption = "Lock Formulas"
   
   
Else
    Sheet1.CommandButton3.Caption = "Refresh"
   End If

EKNFormula = True

End Function
Public Function iRefresh() As Integer

iRefresh = 0
While iRefresh < 55
    On Error Resume Next
     iRefresh = iRefresh + 1
    DoEvents
Wend
ActiveSheet.Calculate
DoEvents
iRefresh = 1

End Function
Microsoft Excel

Avatar of undefined
Last Comment
leezac

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Robberbaron (robr)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
leezac

Thanks - that is helpful - will try
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck