Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Comment Out Code in Excel

Posted on 2011-09-06
8
Medium Priority
?
278 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

721 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