Link to home
Start Free TrialLog in
Avatar of cpatte7372
cpatte7372Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Comment Out Code in Excel

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
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a single quote.

' This is commented out

Open in new window

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
ASKER CERTIFIED SOLUTION
Avatar of Gemstorm
Gemstorm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of byundt
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.
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
I suggest using Gemstorm's method - in the VBA IDE turn on the Edit Toolbar and use the icons.

Thanks
Avatar of Gemstorm
Gemstorm

Hey Carlton,
Did you get a suitable answer?
Avatar of cpatte7372

ASKER

Gemstorm,

Thanks alot dude. Nice and easy

Cheers