VB basics

dopydette

New Member
Joined
Jan 23, 2003
Messages
29
how can I simplify this code? thank you for your help

Range("SO_Bid_1_1") = 0
Range("SO_Bid_1_2") = 0
Range("SO_Bid_1_3") = 0
Range("SO_Bid_1_4") = 0
Range("SO_Bid_1_5") = 0
Range("SO_Bid_1_6") = 0
Range("SO_Bid_1_7") = 0
Range("SO_Bid_1_8") = 0
Range("SO_Bid_1_9") = 0
Range("SO_Bid_1_10") = 0
Range("SO_Bid_1_11") = 0
Range("SO_Bid_1_12") = 0
Range("SO_Bid_1_13") = 0
Range("SO_Bid_1_14") = 0
Range("SO_Bid_1_15") = 0
Range("SO_Bid_1_16") = 0
Range("SO_Bid_1_1n") = 0
Range("SO_Bid_1_2n") = 0
Range("SO_Bid_1_3n") = 0
Range("SO_Bid_1_4n") = 0
Range("SO_Bid_1_5n") = 0
Range("SO_Bid_1_6n") = 0
Range("SO_Bid_1_7n") = 0
Range("SO_Bid_1_8n") = 0
Range("SO_Bid_1_9n") = 0
Range("SO_Bid_1_10n") = 0
Range("SO_Bid_1_11n") = 0
Range("SO_Bid_1_12n") = 0
Range("SO_Bid_1_13n") = 0
Range("SO_Bid_1_14n") = 0
Range("SO_Bid_1_15n") = 0
Range("SO_Bid_1_16n") = 0

Range("SO_Bid_2_1") = 0
Range("SO_Bid_2_2") = 0
Range("SO_Bid_2_3") = 0
Range("SO_Bid_2_4") = 0
Range("SO_Bid_2_5") = 0
Range("SO_Bid_2_6") = 0
Range("SO_Bid_2_7") = 0
Range("SO_Bid_2_8") = 0
Range("SO_Bid_2_9") = 0
Range("SO_Bid_2_10") = 0
Range("SO_Bid_2_11") = 0
Range("SO_Bid_2_12") = 0
Range("SO_Bid_2_13") = 0
Range("SO_Bid_2_14") = 0
Range("SO_Bid_2_15") = 0
Range("SO_Bid_2_16") = 0
Range("SO_Bid_2_1n") = 0
Range("SO_Bid_2_2n") = 0
Range("SO_Bid_2_3n") = 0
Range("SO_Bid_2_4n") = 0
Range("SO_Bid_2_5n") = 0
Range("SO_Bid_2_6n") = 0
Range("SO_Bid_2_7n") = 0
Range("SO_Bid_2_8n") = 0
Range("SO_Bid_2_9n") = 0
Range("SO_Bid_2_10n") = 0
Range("SO_Bid_2_11n") = 0
Range("SO_Bid_2_12n") = 0
Range("SO_Bid_2_13n") = 0
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
would this work

Code:
Sub SO_Bid()
Dim i As Long, j As Long
For i = 1 To 16
    Range("SO_Bid_1_" & i) = 0
    Range("SO_Bid_1_" & i & "n") = 0
Next i

For j = 1 To 16
    Range("SO_Bid_2_" & i) = 0
    Range("SO_Bid_2_" & i & "n") = 0
Next j

End Sub
 
Upvote 0

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,941
Try this:

Code:
Sub setToZero()
For Each n In ActiveWorkbook.Names
    If Left(n.Name, 6) = "SO_Bid" Then Range(n.Name).Value = 0
Next n
End Sub
But this looks at all the names in a workbook and not a specific sheet.

Hope that helps.
 
Upvote 0

doofusboy

Well-known Member
Joined
Oct 14, 2003
Messages
1,325
If those are all range names, you could use:

Code:
Dim n As Name
    For Each n In ThisWorkbook.Names
        If Mid(n.Name, 1, 6) = "SO_Bid" Then
            Range(n.Name).Value = 0
        End If
    Next n
 
Upvote 0

Forum statistics

Threads
1,191,172
Messages
5,985,086
Members
439,940
Latest member
Kyrad42

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
Top