insert zero's with code?

cheveley

Active Member
Joined
Sep 24, 2002
Messages
273
i would like to insert a zero in each cell in the range L74:P75 with code but i can only do this the long way for each cell by recording the macro.

could anyone suggest some code that would do this neatly?

much obliged
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi

You could put a command button on the sheet (I've done it on sheet1)

right click the button and make the code thus:
Code:
Private Sub CommandButton1_Click()

For Each c In Sheets("sheet1").Range("L74:P75")
    c.Value = "0"
Next
End Sub
That should get you started.
 
Upvote 0
Thanks. My range is called "pefix" and i have changed the macro so that it forms part of a large macro but I am running into problems. my code is:

Range ("pefix")
c.Value = "0"
 
Upvote 0
.......in that case, just use this bit........

Code:
For Each c In Sheets("sheet1").Range("pefix")
    c.Value = "0"
Next
......... obviously change the sheet reference to suit...

PS I presume it's not meant to read "Prefix" is it?
 
Upvote 0
Looping is generally fairly slow and most VBA gurus on this board recommend avoiding loops if possible. Try this code:

<font face=Courier New>    Application.Goto Reference:="pefix"
    Selection.FormulaR1C1 = "0"</FONT>
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,185
Members
448,554
Latest member
Gleisner2

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