PC Review


Reply
Thread Tools Rate Thread

Clear Contents Macro

 
 
MSE
Guest
Posts: n/a
 
      21st Jun 2008
I have a workbook with six worksheets. On Sheet 6, I want to create a macro
linked to an Excel button from the forms toolbar. I want the macro to only
clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5 in the
following cells C7, C9, C16:C23, and C26:C33. I am trying to write a code
that will do this, any thoughts?

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      21st Jun 2008
try this.

Sub clearcellsonsheets()
For i = 1 To 5
ms = "sheet" & i
Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
Next i
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"MSE" <(E-Mail Removed)> wrote in message
news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
>I have a workbook with six worksheets. On Sheet 6, I want to create a
>macro
> linked to an Excel button from the forms toolbar. I want the macro to
> only
> clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5 in
> the
> following cells C7, C9, C16:C23, and C26:C33. I am trying to write a code
> that will do this, any thoughts?
>


 
Reply With Quote
 
MSE
Guest
Posts: n/a
 
      21st Jun 2008
Thank you for your input. When I try to run the Macro the screen switches
to visual basic and I get a message that says Run-time error '9' Subscript
out of range, Continue, End, Debug, Help. Any thoughts?

"Don Guillett" wrote:

> try this.
>
> Sub clearcellsonsheets()
> For i = 1 To 5
> ms = "sheet" & i
> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
> Next i
> End Sub
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "MSE" <(E-Mail Removed)> wrote in message
> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
> >I have a workbook with six worksheets. On Sheet 6, I want to create a
> >macro
> > linked to an Excel button from the forms toolbar. I want the macro to
> > only
> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5 in
> > the
> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write a code
> > that will do this, any thoughts?
> >

>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      21st Jun 2008

Number of sheets? Name of sheets?
If desired, send your workbook with these snippets and the code to my
address below

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"MSE" <(E-Mail Removed)> wrote in message
news4572E32-3865-4261-96C2-(E-Mail Removed)...
> Thank you for your input. When I try to run the Macro the screen
> switches
> to visual basic and I get a message that says Run-time error '9' Subscript
> out of range, Continue, End, Debug, Help. Any thoughts?
>
> "Don Guillett" wrote:
>
>> try this.
>>
>> Sub clearcellsonsheets()
>> For i = 1 To 5
>> ms = "sheet" & i
>> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
>> Next i
>> End Sub
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "MSE" <(E-Mail Removed)> wrote in message
>> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
>> >I have a workbook with six worksheets. On Sheet 6, I want to create a
>> >macro
>> > linked to an Excel button from the forms toolbar. I want the macro to
>> > only
>> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5
>> > in
>> > the
>> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write a
>> > code
>> > that will do this, any thoughts?
>> >

>>
>>


 
Reply With Quote
 
MSE
Guest
Posts: n/a
 
      21st Jun 2008
I have six sheets. Their names are Sheet 1, Sheet 2, Sheet 3, Sheet 4, Sheet
5, and Sheet 6. This part of the code is having the problem I think.

Sheets(ms).Range("C7,C9,C16:C23,C26:C33").ClearContents

It gets highlighted in yellow with a yellow arrow pointing to it when I try
to run the macro. Any ideas?



"Don Guillett" wrote:

>
> Number of sheets? Name of sheets?
> If desired, send your workbook with these snippets and the code to my
> address below
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "MSE" <(E-Mail Removed)> wrote in message
> news4572E32-3865-4261-96C2-(E-Mail Removed)...
> > Thank you for your input. When I try to run the Macro the screen
> > switches
> > to visual basic and I get a message that says Run-time error '9' Subscript
> > out of range, Continue, End, Debug, Help. Any thoughts?
> >
> > "Don Guillett" wrote:
> >
> >> try this.
> >>
> >> Sub clearcellsonsheets()
> >> For i = 1 To 5
> >> ms = "sheet" & i
> >> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
> >> Next i
> >> End Sub
> >> --
> >> Don Guillett
> >> Microsoft MVP Excel
> >> SalesAid Software
> >> (E-Mail Removed)
> >> "MSE" <(E-Mail Removed)> wrote in message
> >> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
> >> >I have a workbook with six worksheets. On Sheet 6, I want to create a
> >> >macro
> >> > linked to an Excel button from the forms toolbar. I want the macro to
> >> > only
> >> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5
> >> > in
> >> > the
> >> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write a
> >> > code
> >> > that will do this, any thoughts?
> >> >
> >>
> >>

>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      21st Jun 2008
Send your workbook to my address below and I'll have a look

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"MSE" <(E-Mail Removed)> wrote in message
news:31A4A3C7-485D-4FC9-9441-(E-Mail Removed)...
>I have six sheets. Their names are Sheet 1, Sheet 2, Sheet 3, Sheet 4,
>Sheet
> 5, and Sheet 6. This part of the code is having the problem I think.
>
> Sheets(ms).Range("C7,C9,C16:C23,C26:C33").ClearContents
>
> It gets highlighted in yellow with a yellow arrow pointing to it when I
> try
> to run the macro. Any ideas?
>
>
>
> "Don Guillett" wrote:
>
>>
>> Number of sheets? Name of sheets?
>> If desired, send your workbook with these snippets and the code to my
>> address below
>>
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "MSE" <(E-Mail Removed)> wrote in message
>> news4572E32-3865-4261-96C2-(E-Mail Removed)...
>> > Thank you for your input. When I try to run the Macro the screen
>> > switches
>> > to visual basic and I get a message that says Run-time error '9'
>> > Subscript
>> > out of range, Continue, End, Debug, Help. Any thoughts?
>> >
>> > "Don Guillett" wrote:
>> >
>> >> try this.
>> >>
>> >> Sub clearcellsonsheets()
>> >> For i = 1 To 5
>> >> ms = "sheet" & i
>> >> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
>> >> Next i
>> >> End Sub
>> >> --
>> >> Don Guillett
>> >> Microsoft MVP Excel
>> >> SalesAid Software
>> >> (E-Mail Removed)
>> >> "MSE" <(E-Mail Removed)> wrote in message
>> >> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
>> >> >I have a workbook with six worksheets. On Sheet 6, I want to create
>> >> >a
>> >> >macro
>> >> > linked to an Excel button from the forms toolbar. I want the macro
>> >> > to
>> >> > only
>> >> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet
>> >> > 5
>> >> > in
>> >> > the
>> >> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write
>> >> > a
>> >> > code
>> >> > that will do this, any thoughts?
>> >> >
>> >>
>> >>

>>
>>


 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      21st Jun 2008
Try changing "sheet" to "Sheet"


Gord Dibben MS Excel MVP

On Sat, 21 Jun 2008 10:12:00 -0700, MSE <(E-Mail Removed)> wrote:

>Thank you for your input. When I try to run the Macro the screen switches
>to visual basic and I get a message that says Run-time error '9' Subscript
>out of range, Continue, End, Debug, Help. Any thoughts?
>
>"Don Guillett" wrote:
>
>> try this.
>>
>> Sub clearcellsonsheets()
>> For i = 1 To 5
>> ms = "sheet" & i
>> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
>> Next i
>> End Sub
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "MSE" <(E-Mail Removed)> wrote in message
>> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
>> >I have a workbook with six worksheets. On Sheet 6, I want to create a
>> >macro
>> > linked to an Excel button from the forms toolbar. I want the macro to
>> > only
>> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5 in
>> > the
>> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write a code
>> > that will do this, any thoughts?
>> >

>>
>>


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Jun 2008
If your sheet names really have that space character, then change:

ms = "sheet" & i
to
ms = "sheet " & i



MSE wrote:
>
> I have six sheets. Their names are Sheet 1, Sheet 2, Sheet 3, Sheet 4, Sheet
> 5, and Sheet 6. This part of the code is having the problem I think.
>
> Sheets(ms).Range("C7,C9,C16:C23,C26:C33").ClearContents
>
> It gets highlighted in yellow with a yellow arrow pointing to it when I try
> to run the macro. Any ideas?
>
> "Don Guillett" wrote:
>
> >
> > Number of sheets? Name of sheets?
> > If desired, send your workbook with these snippets and the code to my
> > address below
> >
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > (E-Mail Removed)
> > "MSE" <(E-Mail Removed)> wrote in message
> > news4572E32-3865-4261-96C2-(E-Mail Removed)...
> > > Thank you for your input. When I try to run the Macro the screen
> > > switches
> > > to visual basic and I get a message that says Run-time error '9' Subscript
> > > out of range, Continue, End, Debug, Help. Any thoughts?
> > >
> > > "Don Guillett" wrote:
> > >
> > >> try this.
> > >>
> > >> Sub clearcellsonsheets()
> > >> For i = 1 To 5
> > >> ms = "sheet" & i
> > >> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
> > >> Next i
> > >> End Sub
> > >> --
> > >> Don Guillett
> > >> Microsoft MVP Excel
> > >> SalesAid Software
> > >> (E-Mail Removed)
> > >> "MSE" <(E-Mail Removed)> wrote in message
> > >> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
> > >> >I have a workbook with six worksheets. On Sheet 6, I want to create a
> > >> >macro
> > >> > linked to an Excel button from the forms toolbar. I want the macro to
> > >> > only
> > >> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet 5
> > >> > in
> > >> > the
> > >> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write a
> > >> > code
> > >> > that will do this, any thoughts?
> > >> >
> > >>
> > >>

> >
> >


--

Dave Peterson
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      21st Jun 2008
Sub clearcellsonsheets()
For i = 1 To Worksheets.Count
If Sheets(i).Name <> "Department Total" Then
Sheets(i).Range("C7,C9,c16:C23,C26:C33").ClearContents
End If
Next i
End Sub

Didn't work so I changed to ABOVE & suggested other changes to wb
'Sub clearcellsonsheetsold()
'For i = 1 To 5
'ms = "Sheet " & i
'Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
'Next i
'End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Send your workbook to my address below and I'll have a look
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "MSE" <(E-Mail Removed)> wrote in message
> news:31A4A3C7-485D-4FC9-9441-(E-Mail Removed)...
>>I have six sheets. Their names are Sheet 1, Sheet 2, Sheet 3, Sheet 4,
>>Sheet
>> 5, and Sheet 6. This part of the code is having the problem I think.
>>
>> Sheets(ms).Range("C7,C9,C16:C23,C26:C33").ClearContents
>>
>> It gets highlighted in yellow with a yellow arrow pointing to it when I
>> try
>> to run the macro. Any ideas?
>>
>>
>>
>> "Don Guillett" wrote:
>>
>>>
>>> Number of sheets? Name of sheets?
>>> If desired, send your workbook with these snippets and the code to my
>>> address below
>>>
>>> --
>>> Don Guillett
>>> Microsoft MVP Excel
>>> SalesAid Software
>>> (E-Mail Removed)
>>> "MSE" <(E-Mail Removed)> wrote in message
>>> news4572E32-3865-4261-96C2-(E-Mail Removed)...
>>> > Thank you for your input. When I try to run the Macro the screen
>>> > switches
>>> > to visual basic and I get a message that says Run-time error '9'
>>> > Subscript
>>> > out of range, Continue, End, Debug, Help. Any thoughts?
>>> >
>>> > "Don Guillett" wrote:
>>> >
>>> >> try this.
>>> >>
>>> >> Sub clearcellsonsheets()
>>> >> For i = 1 To 5
>>> >> ms = "sheet" & i
>>> >> Sheets(ms).Range("C7,C9,c16:C23,C26:C33").ClearContents
>>> >> Next i
>>> >> End Sub
>>> >> --
>>> >> Don Guillett
>>> >> Microsoft MVP Excel
>>> >> SalesAid Software
>>> >> (E-Mail Removed)
>>> >> "MSE" <(E-Mail Removed)> wrote in message
>>> >> news:CB51A454-35EE-44F9-9B32-(E-Mail Removed)...
>>> >> >I have a workbook with six worksheets. On Sheet 6, I want to create
>>> >> >a
>>> >> >macro
>>> >> > linked to an Excel button from the forms toolbar. I want the macro
>>> >> > to
>>> >> > only
>>> >> > clear the contents of Sheet 1, Sheet 2, Sheet 3, Sheet 4, and Sheet
>>> >> > 5
>>> >> > in
>>> >> > the
>>> >> > following cells C7, C9, C16:C23, and C26:C33. I am trying to write
>>> >> > a
>>> >> > code
>>> >> > that will do this, any thoughts?
>>> >> >
>>> >>
>>> >>
>>>
>>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to clear contents and put an X bevchapman Microsoft Excel Misc 3 17th Mar 2009 07:03 PM
Macro to clear range contents when cell contents are changed by us =?Utf-8?B?U3RldmUgRQ==?= Microsoft Excel Programming 12 22nd Feb 2007 09:09 PM
Clear Contents Macro =?Utf-8?B?V0JUS2JlZXp5?= Microsoft Excel Programming 1 16th Nov 2006 10:50 PM
Clear contents macro =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Programming 10 6th Apr 2006 07:41 PM
Need macro to clear contents =?Utf-8?B?c3RldmVfc3Iy?= Microsoft Excel Programming 4 28th Feb 2006 09:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 PM.