Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Simple For Each Next code


"jacqui" wrote in message
...
I'm trying to write a simple For Each statement to loop
through each worksheet in the active workbook. I should
know how to do this but for some reason I'm having a bit
of trouble. Can anyone help? The code I've written so
far is below. I'm getting a VBA error though on the shts
() = Sheets(iCnt) line where Excel says 'Can't assign to
array'.
I'm sure it could also be simpler too, so if there's a
much neater way, I'd be very grateful for any other
suggestions.
Many thanks
Jacqui

Dim iCnt As Integer

Dim sRTitle As String
Dim sht() As Worksheet

ActiveWindow.SelectedSheets.Copy

ActiveWindow.Caption = "ERS-Formula to value"
Application.StatusBar = "Converting formula to
values"

iCnt = Worksheets.Count
sht() = Sheets(iCnt)

For Each sht(iCnt) In Worksheets

EndRow = Range("A65000").End(xlUp).Row + 1
iCCount = Range("IV7").End(xlToLeft).Column

Range("A1", Cells(EndRow, iCCount)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

iCnt = iCnt + 1

Next


The variable sht needs to be an object not an array
and you need to iterate through each one in turn
in the Workbook,something like this

Dim mysht as Worksheet

For Each mysht in ActiveWorkbook.Worksheets

Msgbox mysht.name

Next mysht

Set mysht = Nothing

Keith


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
Simple code for shifting N.F[_2_] Excel Discussion (Misc queries) 1 July 6th 07 10:38 PM
Help with some simple code Angeline Excel Discussion (Misc queries) 4 October 12th 06 09:06 AM
Simple Code, I think... [email protected] Excel Worksheet Functions 1 August 2nd 06 08:09 PM
Simple Checkbox Message Code nemadrias Excel Discussion (Misc queries) 10 June 21st 06 08:59 PM
Simple For Each Next code Marek S. Excel Programming 0 July 28th 03 12:34 PM


All times are GMT +1. The time now is 07:53 AM.

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"