+ Reply to Thread
Results 1 to 2 of 2

Thread: Debugging VBA

  1. #1
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,778

    Debugging VBA

    The purpose of this thread is to assist users in debugging VBA. It's intended to be a source of links in other threads to which we can vector members for basic debugging. Learning to debug is the very best way to improve your coding skills, and I invite participation by all members who provide accurate, useful, and concise descriptions of methods.

    This is not a question forum, and all questions will be unceremoniously deleted. If you have a question, start a new thread and provide a link in the relevant post in this thread.

    For starters, I highly commend http://www.cpearson.com/excel/Debug.htm as a point of departure.
    Last edited by shg; 06-30-2010 at 12:38 AM.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  2. #2
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,778

    Re: Debugging VBA

    The Evaluate function is a powerful capability of VBA to modify contiguous ranges without loops, and Forum Guru DonkeyOte is particularly adept in its use. Here's an example of mine from http://www.excelforum.com/excel-prog...-function.html.
    Sub x()
        Dim r As Range
        Dim sAdr As String
        Dim sFrm As String
        
        Set r = Selection.Cells
        r.NumberFormat = "@"
        sAdr = r.Address
        sFrm = "if(row(" & sAdr & "), text(" & sAdr & ",""dd-mm-yyyy""))"
        'Debug.Print sFrm
        r.Value = Evaluate(sFrm)
    End Sub
    The point of the example is not to explain the problem it solves. Rather, the purpose it to show that the formula to be evaluated is first constructed as a string, which is then (in the statement that is commented out) printed to the Immediate window to verify that it is well-formed and appropriate. It's easier to look at the formula in the Immediate window than to try to sort out a run-time 1004 error without ever seeing the problematic formula.
    Last edited by shg; 07-05-2010 at 01:04 AM. Reason: deleted unneeded declaration as noted by foxguy
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0