Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default For...Next Loop

What did I learn? Excellent question! I tried to declare A as a variable,
and after running through the first iteration of the loop I though I had to
increment by one, or basically, A = A + 1. I thought this was a necessary
element of the loop. I guess JE McGimpseys code does all of this with the
For Each ws and Next ws. Also, I needed to declare a variable as Worksheet
and I needed to declare two variables as Range. In my code, I didnt declare
a variable as Worksheet, and only declared one variable as Range. I tried to
set my destination range as B3, and then tried to Offset by one with the I
variable, which was never declared. Im not sure what the following does:
rDest.Offset(0, -1).Value = ws.Name I put a tick mark in front of it, ran the
code, and it seemed to work fine. Also, Im not sure I fully understand the
following: rDest.Resize(1, .Columns.Count).Value = .Value I would have
thought it was something like rDest.Resize(1, 0).Value = .Value However,
when I tried this it failed, so I hit Ctrl Z. Is all of this, or any of
this, right? Im fascinated by this stuff. I know I still have a lot to
learn. Im trying to understand this particular concept so I can apply this
to many other types of scenarios; Im striving to resolve my own problems
and, of course, assist others when needed.
--
RyGuy


"Tom Ogilvy" wrote:

What did you learn?

--
Regards,
Tom Ogilvy


"ryguy7272" wrote:

THAT'S IT JE McGimpsey!!! That gives me the result I was looking for!!
Another day, another lesson learned!

Thanks so much!
--
RyGuy


"JE McGimpsey" wrote:

I'm not sure I have it exactly the way you want it, but try:

Public Sub ListData()
Dim ws As Worksheet
Dim rCopy As Range
Dim rDest As Range

Set rDest = ActiveWorkbook.Worksheets("Summary").Range("B3")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < "Summary" Then
rDest.Offset(0, -1).Value = ws.Name
With ws.Range("B39:T39")
rDest.Resize(1, .Columns.Count).Value = .Value
End With
Set rDest = rDest.Offset(1, 0)
End If
Next ws
End Sub



In article ,
ryguy7272 wrote:

Between using the macro recorder and recycling some code that I found on this
DG a while back, I tried to create a simple loop to select a range of cells
on each sheet in my workbook, and copy/paste the values into 'Summary'. I
donテ「ぎ┐t want to copy the Range("B39:T39") from the テ「ぎヒ彜ummaryテ「ぎ┐, but I do want it
from all other sheetsテ「ぎツヲ.and then copy/paste it to the テ「ぎヒ彜ummaryテ「ぎ┐. Should be a
simple fixテ「ぎツヲI hopeテ「ぎツヲ


Code listed below; would someone please explain what I am doing wrong:

Sub ListData()

Dim A As Integer
Dim rng2 As Range
Set rng2 = Range("B3")

For Each rng2 In ActiveWorkbook.Sheets
If (Sheet.Name) < "Summary" Then

Range("B39:T39").Select
Selection.Copy

Sheets("Summary").Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

rng2.Offset(I, 0).Value = Sheet.Name
A = A + 1
End If
Next rng2

End Sub


PS, sorry if this double-posts...I think I just got kicked out of my
original posting window...

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
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 09:56 PM.

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

About Us

"It's about Microsoft Excel"