Solved

Comment Out Code in Excel

Posted on 2011-09-06
8
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

739 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