Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Another ARRAY Question...

Is it possible to set a range as an array using the ("A1:A10") style, or 2
named ranges such as("firstRecord:lastRecord") rather than typing each cell
in ("A1","A2","A3"...etc)?

Also, since this array will change each time the sheet is used, is it
possible to count the number of values that appear in the array to use in a
For, Next loop?

I'm basically moving data if a cell contained in the array contains an 'x'

code below if any help.

Thanks

Trevor

Sub Converted()

myRows = Worksheets("Tracker").Range("first_entry:last_entr y").Rows.Count
MyValues = Array("D6", "D7", "D8", "D9", "D10")

For i = 0 To myRows - 1

If Worksheets("Tracker").Range(MyValues(i)) = "x" Then
Worksheets("Tracker").Range("B6:c6").Offset(i, 0).Copy
Range("last_test").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If

Next i

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Another ARRAY Question...

Most wouldn't use an array for contiguous cells.

dim rng as Range
Dim cell as Range
set rng = Worksheets("Tracker").Range("D6:D10")
for each cell in rng

next cell

to loop through an array

MyValues = Array("D6", "D7", "D8", "D9", "D10")

for i = lbound(myValues) to ubound(myvalues)

Next i

--
Regards,
Tom Ogilvy


"Trevor Williams" wrote:

Is it possible to set a range as an array using the ("A1:A10") style, or 2
named ranges such as("firstRecord:lastRecord") rather than typing each cell
in ("A1","A2","A3"...etc)?

Also, since this array will change each time the sheet is used, is it
possible to count the number of values that appear in the array to use in a
For, Next loop?

I'm basically moving data if a cell contained in the array contains an 'x'

code below if any help.

Thanks

Trevor

Sub Converted()

myRows = Worksheets("Tracker").Range("first_entry:last_entr y").Rows.Count
MyValues = Array("D6", "D7", "D8", "D9", "D10")

For i = 0 To myRows - 1

If Worksheets("Tracker").Range(MyValues(i)) = "x" Then
Worksheets("Tracker").Range("B6:c6").Offset(i, 0).Copy
Range("last_test").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If

Next i

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Another ARRAY Question...

Brilliant - thanks Tom, once again you've come to the rescue.

Trevor

"Tom Ogilvy" wrote:

Most wouldn't use an array for contiguous cells.

dim rng as Range
Dim cell as Range
set rng = Worksheets("Tracker").Range("D6:D10")
for each cell in rng

next cell

to loop through an array

MyValues = Array("D6", "D7", "D8", "D9", "D10")

for i = lbound(myValues) to ubound(myvalues)

Next i

--
Regards,
Tom Ogilvy


"Trevor Williams" wrote:

Is it possible to set a range as an array using the ("A1:A10") style, or 2
named ranges such as("firstRecord:lastRecord") rather than typing each cell
in ("A1","A2","A3"...etc)?

Also, since this array will change each time the sheet is used, is it
possible to count the number of values that appear in the array to use in a
For, Next loop?

I'm basically moving data if a cell contained in the array contains an 'x'

code below if any help.

Thanks

Trevor

Sub Converted()

myRows = Worksheets("Tracker").Range("first_entry:last_entr y").Rows.Count
MyValues = Array("D6", "D7", "D8", "D9", "D10")

For i = 0 To myRows - 1

If Worksheets("Tracker").Range(MyValues(i)) = "x" Then
Worksheets("Tracker").Range("B6:c6").Offset(i, 0).Copy
Range("last_test").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If

Next i

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
Array Question keeblerjp Excel Discussion (Misc queries) 4 June 20th 06 04:21 PM
For Each Array Question mvyvoda Excel Programming 1 June 12th 06 06:34 PM
Array Question Frederick Chow Excel Programming 3 March 10th 05 06:16 PM
Array question mickiedevries[_9_] Excel Programming 3 August 24th 04 06:58 PM
Array Question hotherps[_88_] Excel Programming 2 July 30th 04 11:26 AM


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