Solved

Comment Out Code in Excel

Posted on 2011-09-06
8
259 Views
Last Modified: 2012-05-12
Hello Experts,

Very simple one.

Can you please let me know how to comment out some code. I don't want to delete it just don't need it at the moment.

So I have the following code.

Private Sub Worksheet_Calculate()
Dim cel As Range
Dim Addr As Variant, Targ As Variant
Static Stocks(3) As Double      'Starts with element 0
Dim i As Long, n As Long

'Added code
    If ActiveSheet.Range("AQ3").Value > 85 Or ActiveSheet.Range("AV3").Value > 85 Then
        Call soundAlert(True)
    Else
        Call soundAlert(False)
    End If
   
Addr = Array("AQ3", "AV3", "AP3", "AU3")    'Watch these cells for price changes
Targ = Array(85, 85, 20, 20)                'Look for prices above these threshhold values
n = UBound(Stocks)
For i = 0 To n
    With Range(Addr(i))
        If Not IsError(.Value) Then
            If Stocks(i) <> .Value Then
                Stocks(i) = .Value
                If .Value > Targ(i) Then
                    Open "C:\Users\User\Documents\ABC.txt" For Append As #1  'Change path & name to suit
                    Write #1, .Address(False, False), .Value, Date, Format(Time, "hh:mm:ss.ss")
                    Close 1
                End If
            End If
        End If
    End With
Next
End Sub

But I don't need the following at the moment:

Addr = Array("AQ3", "AV3", "AP3", "AU3")    'Watch these cells for price changes
Targ = Array(85, 85, 20, 20)                'Look for prices above these threshhold values
n = UBound(Stocks)
For i = 0 To n
    With Range(Addr(i))
        If Not IsError(.Value) Then
            If Stocks(i) <> .Value Then
                Stocks(i) = .Value
                If .Value > Targ(i) Then
                    Open "C:\Users\User\Documents\ABC.txt" For Append As #1  'Change path & name to suit
                    Write #1, .Address(False, False), .Value, Date, Format(Time, "hh:mm:ss.ss")
                    Close 1
                End If
            End If
        End If
    End With
Next
End Sub

Just need guidance on how to comment it out.

Cheers

Carlton
0
Comment
Question by:cpatte7372
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 36488521
Use a single quote.

' This is commented out

Open in new window

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 36488542
I think there may be a keyboard shortcut to toggle comments on/off on multiple lines.

There is in MSSQL Studio (CTRL+K, C and CTRL+K, U), but that doesn't work in Excel.

But I found this article How to quickly (really quickly) comment out blocks of code
0
 
LVL 3

Accepted Solution

by:
Gemstorm earned 500 total points
ID: 36488557
In your VBE, click on View... Toolbars... and make sure the Edit toolbar is ticked.
There are two icons on that toolbar that allow you to comment and uncomment blocks of code.

Simply highlight the lines/block you want and toggle the buttons...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 81

Expert Comment

by:byundt
ID: 36488608
I would add a statement to exit the sub at the desired point:
Exit Sub
Addr = Array("AQ3", "AV3", "AP3", "AU3")    'Watch these cells for price changes

Open in new window


You can easily delete that statement (or comment it out) when you need the statements that follow.
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36489659
I use this age old technique:

as you can see, 1 will never equal zero and will always jump over the code.  just remember to remove both lines before launching - thus the code word: "TODO"


Public Sub test()

    ' TODO - COMMENTED OUT FOR TESTING
    If 1 = 0 Then
   
            'This is a test
           
            For a = 1 To 100
                Debug.Print "test " & a
            Next a
   
    ' TODO - COMMENTED OUT FOR TESTING
    End If


End Sub
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36490336
I suggest using Gemstorm's method - in the VBA IDE turn on the Edit Toolbar and use the icons.

Thanks
0
 
LVL 3

Expert Comment

by:Gemstorm
ID: 36497373
Hey Carlton,
Did you get a suitable answer?
0
 

Author Closing Comment

by:cpatte7372
ID: 36519702
Gemstorm,

Thanks alot dude. Nice and easy

Cheers
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question