View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default VBA "=STEP" equivalent

On Monday, November 18, 2019 at 6:57:22 PM UTC-6, GS wrote:
For years all macros I wrote for Excel were in XLM code. Trying to learn
VBA and would like to know if there is a VBA equivalent to the "=STEP()"
statement in XLM, which is very useful in debugging.

Can someone please indicate what the corresponding code is for VBA? Many
thanks.


Unable to find any reference resources for XLM Step(); - can you point or OR
explain what it does?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


It's a macro function for Excel 4.0 (yes, really old!)

As described in the manual:

"Stops the normal flow of a macro and calculates it one cell at a time.
Running a macro one cell at a time is called single-stepping and is very
useful when you are debugging a macro."

At each step it gives user the option to continue stepping, or running the
rest of the macro normally, without interruption.

Hopefully this describes it. I appreciate your help, Garry.


That's what I suspected it was based on unclear info found online. I started
programming Excel with Office 2000 Developer Edition so I know nothing of XLM
macros.

In VBA you can step thru code 1 line at a time, whether it's part of a loop or
just executable line after executable line using F8. For example:

Dim vData, rng, n&, k&
vData = ActiveSheet.UsedRange

'Step through 1 cell at a time
For Each rng in ActiveSheet.UsedRange
Debug.Print rng.Value
Next 'rng

'Step through 1 row at a time
For n = LBound(vData) to UBound(vData)
'Step through 1 col at a time
For k = LBound(vData) to UBound(vData, 2)
Debug.Print vData(n, k)
Next 'k
Next 'n

There's also a Step function for loops using a counter:

'Grab data from every other col
For n = LBound(vData) to UBound(vData)
For k = LBound(vData) to UBound(vData, 2) Step 2
Debug.Print vData(n, k)
Next 'k
Next 'n

'Grab data from every other row
For n = LBound(vData) to UBound(vData) Step 2
'Step through 1 col at a time
For k = LBound(vData) to UBound(vData, 2)
Debug.Print vData(n, k)
Next 'k
Next 'n

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion