Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Hi,

Can anyone suggest how I can loop between two sheets within a workbook
please? I do not know how many sheets there will be in the workbook, but I
do know the names of two of them. It is between these two sheets ("FRONT"
and "END") that I wish to loop and paste data into.

Any advice greatly appreciated.

Thanks,

Ewan.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Hi Ewan7279,

Can anyone suggest how I can loop between two sheets within a workbook
please? I do not know how many sheets there will be in the workbook, but I
do know the names of two of them. It is between these two sheets ("FRONT"
and "END") that I wish to loop and paste data into.


Dim oSh as worksheet
Dim bFirstPassed as Boolean
For Each oSh in Thisworkbook.Worksheets
If bFirstPassed Then
'Do your thing!
End If
If oSh.Name="FRONT" Then bFirstPassed=True
If oSh.Name="END" Then Exit For
Next

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Hi, if I understand you, each sheet between "Front" and "End" you wish
to insert some data.

Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name < "Front" OR WS.Name < "End"
'Code to insert data
End If
Next

Let me know if this is not what you were aiming to do. HTH--Lonnie M.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

P.S. I left out the 'Then' at the end of the 'IF' statement. Sorry,
about that.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Hi Lonnie,

Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name < "Front" OR WS.Name < "End"
'Code to insert data
End If
Next


This will add the info to any sheet, because

1. the If clause always yields true (needs to be AND, not OR)
2. Sheets before and after Front and end are also accepted.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Hi Jan and Lonnie,

Thanks for the input!! I will go with Jan's approach, as there are a number
of sheets at the front of the workbook that I do not wish to paste data into,
and as he saya in this posting, the IF statement will add info into those
sheets. I'll let you know how I get on.

Thanks again,

Ewan.

"Jan Karel Pieterse" wrote:

Hi Lonnie,

Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name < "Front" OR WS.Name < "End"
'Code to insert data
End If
Next


This will add the info to any sheet, because

1. the If clause always yields true (needs to be AND, not OR)
2. Sheets before and after Front and end are also accepted.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

In the end I've used a different solution:

As the workbook is user defined in size and format, I have used the user
input sheet to determine which sheets, and which column of the sheets to
update thus:

Dim CELL As Range, RNG as Range
With Worksheets ("User Input Setup Sheet")
Set RNG = .Range(.Range("C3:C52"), .Range("C3:C52").End(xlDown))
End With

Select Case Sheets ("User Choose Column Sheet").Range("B3").Value
Case "1":
Sheets ("Data to copy").Range("D7:D761").Copy
For Each CELL In RNG
If CELL < "" Then
Sheets (CELL.Value).Activate
Range ("D7").Activate
Activesheet.Paste
End If
Next
Case "2":
etc etc etc

Thanks again for your input.

Ewan.

"ewan7279" wrote:

Hi Jan and Lonnie,

Thanks for the input!! I will go with Jan's approach, as there are a number
of sheets at the front of the workbook that I do not wish to paste data into,
and as he saya in this posting, the IF statement will add info into those
sheets. I'll let you know how I get on.

Thanks again,

Ewan.

"Jan Karel Pieterse" wrote:

Hi Lonnie,

Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name < "Front" OR WS.Name < "End"
'Code to insert data
End If
Next


This will add the info to any sheet, because

1. the If clause always yields true (needs to be AND, not OR)
2. Sheets before and after Front and end are also accepted.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default LOOP BETWEEN "FRONT" AND "END" SHEETS?

Try something like

Dim Ndx As Long
For Ndx = Worksheets("Front").Index To Worksheets("End").Index
' do something with Worksheets(Ndx)
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"ewan7279" wrote in message
...
Hi,

Can anyone suggest how I can loop between two sheets within a
workbook
please? I do not know how many sheets there will be in the
workbook, but I
do know the names of two of them. It is between these two
sheets ("FRONT"
and "END") that I wish to loop and paste data into.

Any advice greatly appreciated.

Thanks,

Ewan.



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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM


All times are GMT +1. The time now is 12:32 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"