Solved

Comment Out Code in Excel

Posted on 2011-09-06
8
230 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:RQuadling
ID: 36488521
Use a single quote.

' This is commented out

Open in new window

0
 
LVL 40

Expert Comment

by:RQuadling
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
 
LVL 80

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
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…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now