98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Macro runs correctly, but only by running step by step (f8)
Macro runs correctly, but only by running step by step (f8)
Resolved · High Priority · Version 2010
Damien has attended:
Excel VBA Intro Intermediate course
Macro runs correctly, but only by running step by step (f8)
Hi there,
I have written a long macro whose purpose is to format tabs in a spreadsheet a certain way, count the number of entries in each spreadsheet and provide a summary on the first tab.
This macro works exactly the way I need it to when I go through it step by step (or even holding down f8), however when running the macro any other way, it seems that the macro skips a certain step of the code:
Dim MemChk As Range
Set MemChk = Worksheets(LpIndex).Rows("1:1").Find("Participating Member").Offset(1, 0)
While MemChk <> ""
If MemChk <> Left(ActiveWorkbook.Name, 3) Then
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 1").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 2").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 3").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 4").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 5").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 6").Column).ClearContents
Cells(MemChk.Row, Worksheets(LpIndex).Rows("1:1").Find("field 7").Column).ClearContents
Set MemChk = MemChk.Offset(1, 0)
Else: Set MemChk = MemChk.Offset(1, 0)
End If
Wend
LpIndex is a reference to the current worksheet being worked on. As mutliple tabs need to be formatted, LpIndex changes when the next worksheet is being used. MemChk is simply a reference cell, when it is equal to the workbook name, it simply moves the reference cell down a row until that row is blank. If the cell value is not equal to the workbook name, then the macro needs to clear specific cells, whose field headers are referenced in the code.
When running through the code step by step, this section works as it should, but running the macro as a whole causes the macro not to clear the cells it should, and as such it appears as though the macro has skipped over the entire section, or possibly was unable to clear the contents correctly. The rest of the macro has no issues I can find.
Let me know if you need any additional information.
RE: Macro runs correctly, but only by running step by step (f8)
Hi Damien
Thanks for getting in touch. Looking at your code I can't see any reason why this wouldn't work. I think we'd need to see it in context of the data to fully understand it.
Are you able to send a copy of the workbook + macro to gary@stl-training.co.uk so I can have a closer look?
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Macro runs correctly, but only by running step by step (f8)
Hi Damien
Thanks for sending that file through. What is the final output? When I run it a summary table is created on Sheet 1, C17:F22.
What else is supposed to happen?
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Macro runs correctly, but only by running step by step (f8)
Hi Gary,
Each of the tabs excluding the first few will also have been formatted. However the operation the above code relates to (which is to delete certain cells from each row if the condition is satisfied) only works correctly when running the macro step by step. All other operations in the macro work correctly.
Many thanks,
Damien
Will be marked as resolved in 5 days
Notice: This is an automated message. Due to inactivity, this forum post will be marked as 'resolved' if there are no further responses in the next 5 days.
Fri 24 Jan 2014: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Turn off AutoComplete in ExcelYou may have noticed when typing into your spreadsheets that if you start to enter labels that begin with the same letters as a label that has been previously entered in the same spreadsheet, Excel will try and automatically complete the text for you. This feature is called AutoComplete. |