Disabling sections of code

Glove303

Board Regular
Joined
Dec 18, 2010
Messages
65
I often wonder if there is a better way to "turn off" sections of code, other than putting ' in front of them.

For example, I want to disable some lines of code, but not remove them because I may decide to use them later. Currently I do the following:
Code:
If Buy_Option Then
    Ticket.StopPrice_Box.Value = Application.WorksheetFunction.Fixed((Ticket.Order_Box.Value - _
    (Ticket.StopPips_Box.Value / iFact)), iDec, True)
    
    Ticket.StopAmount_Box.Value = Application.WorksheetFunction.Fixed((((Ticket.Order_Box.Value - _
    Ticket.StopPrice_Box.Value) * iFact) * Ticket.Stake_Box.Value), 2)
End If

'If Defaults.Priv_Tog.Caption = "Privacy Off" Then
'    If Trades.Cells(2, 19).Value > 0 And Trades.Cells(2, 19) <> "" And _
'    Ticket.StopAmount_Box <> "" And Ticket.StopAmount_Box.Value <> 0 Then
'        Ticket.iCapital_Box = Round(((Ticket.StopAmount_Box.Value / _
'        Trades.Cells(2, 19).Value) * 100), 1)
'    Else
'        Ticket.iCapital_Box = ""
'    End If
'End If

I just wonder if there is a better way than this, like a built in facility within Excel to disable code?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If the sections you need to 'disable' or 'enable' are stand alone sections of code, you could set up a master SUB and call only the sub-routinues you need.
 
Upvote 0
Code:
' change to 1 = 1 when you want to run it 
if 1 = 0 then 

If Defaults.Priv_Tog.Caption = "Privacy Off" Then
    If Trades.Cells(2, 19).Value > 0 And Trades.Cells(2, 19) <> "" And _
    Ticket.StopAmount_Box <> "" And Ticket.StopAmount_Box.Value <> 0 Then
        Ticket.iCapital_Box = Round(((Ticket.StopAmount_Box.Value / _
        Trades.Cells(2, 19).Value) * 100), 1)
    Else
        Ticket.iCapital_Box = ""
    End If
End If

end if
 
Upvote 0
Thanks guys. I think the goto idea, and the if statement idea are both very good and I will use one of these from now on :)
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top