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
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of leezac
leezac

ASKER

Thanks - that is helpful - will try
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo