Consulting

Results 1 to 3 of 3

Thread: Watch Window to jump to cell?

  1. #1

    Watch Window to jump to cell?

    When running through a loop can you put a break on a certain cell or tell it to run beginning at a certain cell to a certain cell?
    I guess I could do this in my code by changing the start counter and end counter...
    But thought maybe the Watch window has this capability? I can only find in the watch window to break on change...
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Hey Doug,

    Place the following code in a module:
    [vba]Sub TestMe()
    Dim rng As Excel.Range

    For Each rng In Range("A1:A10").Cells
    rng.Value = rng.Address(0, 0)
    Next rng
    End Sub[/vba] -Click View-->Watch Window
    -Then Click Debug-->Add Watch... (or just right-click in a blank area of the watch window and click Add Watch...)
    -In the Expression Textbox type in: rng.Address(0, 0) = "A4"
    -Yes, that is meant to be rng and not Range (because I'm evaluating the variable rng that I created)
    -Select the "Beak when value is True" radio button in the Watch Type frame
    -Press OK and run the code. The code will halt when the loop has reached cel "A4".

    Hope this helps!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    An alternative is Debug.Assert.

    In Excel 2000 and later, you can use Debug.Assert statements to cause the code to break if a condition is <b><u>not>/u></b> met. The syntax for Debug.Assert is:

    <b>Debug.Assert (condition)</b>

    where condition expression that returns True (-1) or False (0). If the condition evaluates to False or 0, VBA breaks on that line (see, below).

    An example usage could be within a loop that has an exit within it to test whether the loop has completed successfully.

    Using Malik's example

    [vba]

    Sub TestMe()
    Dim rng As Excel.Range

    For Each rng In Range("A1:A10").Cells
    Debug.Assert rng.Address <> "$A$4"
    rng.Value = rng.Address(0, 0)
    Next rng
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •