Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default For...Each Loop Problem

Hi

I am trying to loop my code for each cell ("DummyCell") within a defined region ("MyRegion"), which is column F for a current region (please see code below). However, instead of looping through each cell, it just assigns DummyCell to the MyRegion

Here is my code

-------------------------------------
Sub LoopTest(

Dim DummyCell as Range, MyRegion as Rang
Dim Value() as Strin
Dim i as Byt

i=

Set MyRegion = Cells(1,1).CurrentRegion.Columns(6

For Each DummyCell in MyRegio

Redim Preserve Value(i
Value(i)=DummyCell.Value <<< Error Here (since it's trying to set it to the value of MyRegion!
i=i+

Next DummyCel

End Su
-----------------------------------------

Could you please help

Thankyou very much

SuperJas.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For...Each Loop Problem

SuperJas try


Sub LoopTest()

Dim DummyCell as Range
Dim MyRegion as Range
Dim Value() as String
Dim i as Integer

i=1

Set MyRegion = Cells(1,1).CurrentRegion.Columns(6)
Redim Value(myregion.cells.count)
For Each DummyCell in MyRegion

Value(i)=DummyCell.Value
i=i+1

Next DummyCell

End Su

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default For...Each Loop Problem

Hi Kieran

Thanks for your help. Unfortunately excel is still setting DummyCell to MyRegion when I did a simple DummyCell.Select test. It's very odd isn't it?

Thanks

SuperJas.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default For...Each Loop Problem

SupeJas,

Add a

..Cells

to

Set MyRegion = Cells(1, 1).CurrentRegion.Columns(6)

to get

Set MyRegion = Cells(1, 1).CurrentRegion.Columns(6).Cells

As written, you are setting MyRegion to a column, and trying to loop through
the columns of column 6 - not the cells.

HTH,
Bernie
MS Excel MVP


"SuperJas" wrote in message
...
Hi,

I am trying to loop my code for each cell ("DummyCell") within a defined

region ("MyRegion"), which is column F for a current region (please see code
below). However, instead of looping through each cell, it just assigns
DummyCell to the MyRegion!

Here is my code:

--------------------------------------
Sub LoopTest()

Dim DummyCell as Range, MyRegion as Range
Dim Value() as String
Dim i as Byte

i=1

Set MyRegion = Cells(1,1).CurrentRegion.Columns(6)

For Each DummyCell in MyRegion

Redim Preserve Value(i)
Value(i)=DummyCell.Value <<< Error Here (since it's trying

to set it to the value of MyRegion!)
i=i+1

Next DummyCell

End Sub
------------------------------------------

Could you please help?

Thankyou very much,

SuperJas.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default For...Each Loop Problem

Fantastic! Thanks Bernie! =

SuperJas.


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
do while loop problem April Excel Discussion (Misc queries) 4 October 18th 09 07:51 PM
loop problem teepee[_3_] Excel Discussion (Misc queries) 3 December 31st 08 11:09 AM
Problem with Loop Mike Excel Programming 7 February 26th 04 09:12 PM
For..Next loop problem Dwaine Horton Excel Programming 1 February 18th 04 12:12 AM
loop problem joao Excel Programming 4 November 6th 03 02:01 PM


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