Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Clearing Ranges from Multiple workbooks.

Hi,

I'm trying to create some code that will open (30) workbooks and clear
multiple named ranges from each workbook. The code opens the workbooks fine
but I get a Global error when code reaches the clearcontents line. The code I
have is listed below, the on error is put in because a few of the workbooks
do not have all three named ranges. All of them have the first two named
ranges but only some of then have the third named range.

Thanks for any help you can provide.

Dim a As Integer
Dim wkbk As Workbook

a = MsgBox("Are you sure you want to clear previous data?", vbQuestion +
vbYesNo, "Budget")
Select Case a
Case vbYes
Run ("OpenWorkbooks")
'On Error Resume Next
For Each wkbk In Workbooks
wkbk.Activate
Range("CAPITALEXP").ClearContents
Range("EXPENSES").ClearContents
Range("INCOME").ClearContents
Next wkbk
Run ("CloseWorkbooks")
Case vbNo
End Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Clearing Ranges from Multiple workbooks.

Try

For Each wkbk In Workbooks
wkbk.Activate
wkbk.Names("CAPITALEXP").ReferstoRange.ClearConten ts
wkbk.Names("EXPENSES").ReferstoRange.ClearContents
wkbk.Names("INCOME").ReferstoRange.ClearContents
Next wkbk

--
Regards,
Tom Ogilvy

"Steve O" wrote in message
...
Hi,

I'm trying to create some code that will open (30) workbooks and clear
multiple named ranges from each workbook. The code opens the workbooks

fine
but I get a Global error when code reaches the clearcontents line. The

code I
have is listed below, the on error is put in because a few of the

workbooks
do not have all three named ranges. All of them have the first two named
ranges but only some of then have the third named range.

Thanks for any help you can provide.

Dim a As Integer
Dim wkbk As Workbook

a = MsgBox("Are you sure you want to clear previous data?", vbQuestion +
vbYesNo, "Budget")
Select Case a
Case vbYes
Run ("OpenWorkbooks")
'On Error Resume Next
For Each wkbk In Workbooks
wkbk.Activate
Range("CAPITALEXP").ClearContents
Range("EXPENSES").ClearContents
Range("INCOME").ClearContents
Next wkbk
Run ("CloseWorkbooks")
Case vbNo
End Select
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Clearing Ranges from Multiple workbooks.

You could use the following

For Each wkbk In Workbooks
wkbk.Activate
wkbk.Sheets(1).Range("CAPITALEXP").ClearContents
wkbk.Sheets(1).Range("EXPENSES").ClearContents
wkbk.Sheets(1).Range("INCOME").ClearContents
Next wkbk

Alok

"Steve O" wrote:

Hi,

I'm trying to create some code that will open (30) workbooks and clear
multiple named ranges from each workbook. The code opens the workbooks fine
but I get a Global error when code reaches the clearcontents line. The code I
have is listed below, the on error is put in because a few of the workbooks
do not have all three named ranges. All of them have the first two named
ranges but only some of then have the third named range.

Thanks for any help you can provide.

Dim a As Integer
Dim wkbk As Workbook

a = MsgBox("Are you sure you want to clear previous data?", vbQuestion +
vbYesNo, "Budget")
Select Case a
Case vbYes
Run ("OpenWorkbooks")
'On Error Resume Next
For Each wkbk In Workbooks
wkbk.Activate
Range("CAPITALEXP").ClearContents
Range("EXPENSES").ClearContents
Range("INCOME").ClearContents
Next wkbk
Run ("CloseWorkbooks")
Case vbNo
End Select
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Clearing Ranges from Multiple workbooks.

Thanks, Alok that cleared all the ranges.

I appreciate your help.

"Alok" wrote:

You could use the following

For Each wkbk In Workbooks
wkbk.Activate
wkbk.Sheets(1).Range("CAPITALEXP").ClearContents
wkbk.Sheets(1).Range("EXPENSES").ClearContents
wkbk.Sheets(1).Range("INCOME").ClearContents
Next wkbk

Alok

"Steve O" wrote:

Hi,

I'm trying to create some code that will open (30) workbooks and clear
multiple named ranges from each workbook. The code opens the workbooks fine
but I get a Global error when code reaches the clearcontents line. The code I
have is listed below, the on error is put in because a few of the workbooks
do not have all three named ranges. All of them have the first two named
ranges but only some of then have the third named range.

Thanks for any help you can provide.

Dim a As Integer
Dim wkbk As Workbook

a = MsgBox("Are you sure you want to clear previous data?", vbQuestion +
vbYesNo, "Budget")
Select Case a
Case vbYes
Run ("OpenWorkbooks")
'On Error Resume Next
For Each wkbk In Workbooks
wkbk.Activate
Range("CAPITALEXP").ClearContents
Range("EXPENSES").ClearContents
Range("INCOME").ClearContents
Next wkbk
Run ("CloseWorkbooks")
Case vbNo
End Select
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing Multiple Filters? Mel Excel Discussion (Misc queries) 5 August 29th 08 10:34 PM
copy dynamic ranges in multiple workbooks based on a data in 1 col jbsand1001 Excel Programming 0 May 18th 05 07:08 PM
How to Link named ranges from multiple Workbooks into a single Wo. PMAP_HELP Excel Discussion (Misc queries) 1 December 14th 04 05:51 PM
Clearing Data ranges from Multiple Worksheets Sam Fowler[_2_] Excel Programming 3 April 12th 04 02:04 AM
Clearing a Column range in Multiple Workbooks Ruan[_3_] Excel Programming 1 August 15th 03 07:43 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"