Problem with F5 but not F8

PKennedyG77

New Member
Joined
Jan 2, 2016
Messages
22
Office Version
  1. 365
Platform
  1. Windows
I have a very simple macro. (Apologies for title error, it is OK with F8 but not OK with F5)
The macro populates a cell which then refreshes the data.
I am then using end(xldown) to find the last row
When I step through this using F8 it works perfectly.
When I use F5 the data does not refresh until the macro is complete and therefore the wrong row is found

Macro is below
Code:
Sub RefreshData()
Dim w As Integer
Dim r As Integer
   
    w = InputBox("What week number are you enquiring about." & vbNewLine & " Current Week is " & Range("r2") & "")
    
            Range("G2") = w
   
    ActiveWorkbook.RefreshAll
      
            r = Range("C6").End(xlDown).Row
    
    MsgBox r
   
End Sub
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hello there. Your problem is probably that the refreshall hasn't finished when you step through quickly. Add a line as shown to your macro:
Code:
Sub RefreshData()
Dim w As Integer
Dim r As Integer

w = InputBox("What week number are you enquiring about." & vbNewLine & " Current Week is " & Range("r2") & "")

Range("G2") = w

ActiveWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
r = Range("C6").End(xlDown).Row

MsgBox r

End Sub
 
Upvote 0
Hi,

I'm guessing, with the ActiveWorkbook.RefreshAll changes the number of used rows in column C?

If so, you can try putting whatever changes the number into a seperate sub and call it in after you refresh the workbook or instead of refreshing, depending on what you want to do.

I tried putting the sequence into the Worksheet_Change event, but that will result in an infinite loop, clearly.

Regards,
Elaszat
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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