cpatte7372
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").V alue > 85 Or ActiveSheet.Range("AV3").V alue > 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\A BC.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\A BC.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
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").V
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\A
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\A
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would add a statement to exit the sub at the desired point:
You can easily delete that statement (or comment it out) when you need the statements that follow.
Exit Sub
Addr = Array("AQ3", "AV3", "AP3", "AU3") 'Watch these cells for price changes
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
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
Thanks
Hey Carlton,
Did you get a suitable answer?
Did you get a suitable answer?
ASKER
Gemstorm,
Thanks alot dude. Nice and easy
Cheers
Thanks alot dude. Nice and easy
Cheers
Open in new window