Adding a messages function in VBA for Excel

A quick script for debugging in Excel. Works like a “print” command in a command line interface – just add Msg(~) comments in your VBA code where you want to know what it’s thinking, and the script will return a line. Newest comments appear at the top. Much more useful than using message boxes!

Public Sub Msg(ByVal str As String)
Dim i As Integer
Dim sheetName As String
Dim col As String
sheetName = "Eplus"
col = "F" 'comments will appear in cell F1 to F101 in sheetname EPlus
For i = 100 To 1 Step -1
 Worksheets(sheetName).Range(col & CStr(i + 1)).value = Worksheets(sheetName).Range(col & CStr(i)).value
Next
Worksheets(sheetName).Range(col & CStr(1)).value = str
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.