JeffGrant
Well-known Member
- Joined
- Apr 7, 2021
- Messages
- 558
- Office Version
- 365
- Platform
- Windows
Hi All,
Everywhere I read I am being told to avoid using Select or Activate as much as possible. And I have done that in my model. However, I have several routines like this one that refreshes a query.
If I don't use select or activate, the query does not run.
Why is this so?
Thanks in advance for the advice.......
Sub SetCurrentTime()
Sheet10.Activate
Set ws = Sheet10
With ws
If Format(Now(), "hh:mm") < Format(.Range("AQ2").Value, "hh:mm") Then
.Range("BG48").Value = Format(.Range("AQ2").Value, "hh:mm")
Else
.Range("BG48").Value = Format(Now(), "hh:mm")
End If
Set rng = .Range("BA39")
rng.ListObject.QueryTable.Refresh BackgroundQuery:=False
.Range("AR6").Value = .Range("BC48").Value
End With
Exit Sub
End Sub
Everywhere I read I am being told to avoid using Select or Activate as much as possible. And I have done that in my model. However, I have several routines like this one that refreshes a query.
If I don't use select or activate, the query does not run.
Why is this so?
Thanks in advance for the advice.......
Sub SetCurrentTime()
Sheet10.Activate
Set ws = Sheet10
With ws
If Format(Now(), "hh:mm") < Format(.Range("AQ2").Value, "hh:mm") Then
.Range("BG48").Value = Format(.Range("AQ2").Value, "hh:mm")
Else
.Range("BG48").Value = Format(Now(), "hh:mm")
End If
Set rng = .Range("BA39")
rng.ListObject.QueryTable.Refresh BackgroundQuery:=False
.Range("AR6").Value = .Range("BC48").Value
End With
Exit Sub
End Sub