Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default How to reverse data in an Array

Dim c() As Integer
Dim ends(20) As Integer
For d = Sheet11.Cells(18, 14).Value - 1 To 0 Step -1
ends(d) = Range("A50000").End(xlUp).Row
c() = ends()
Next d 'end stud loop
ReDim Preserve c(Sheet11.Cells(18, 14).Value - 1)

The data in the table is backwards. I assume due to the step -1? Is
there a VBA command to reverse the data in c() ?

Ex. from 1,2,3...to 3,2,1...

Suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to reverse data in an Array

Something like this

For i = LBound(ary) To UBound(ary) / 2
tmp = ary(UBound(ary) - i)
ary(UBound(ary) - i) = ary(i)
ary(i) = tmp
Next i


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Kevin O'Neill" wrote in message
oups.com...
Dim c() As Integer
Dim ends(20) As Integer
For d = Sheet11.Cells(18, 14).Value - 1 To 0 Step -1
ends(d) = Range("A50000").End(xlUp).Row
c() = ends()
Next d 'end stud loop
ReDim Preserve c(Sheet11.Cells(18, 14).Value - 1)

The data in the table is backwards. I assume due to the step -1? Is
there a VBA command to reverse the data in c() ?

Ex. from 1,2,3...to 3,2,1...

Suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to reverse data in an Array

Why not just change your for statement:

For d = Sheet11.Cells(18, 14).Value - 1 To 0 Step -1
becomes
For d = 0 to Sheet11.Cells(18, 14).Value - 1

But all that did for me was put in the row number of the last used cell in
column A in all the elements of the array.

I bet that's not what you really wanted.

(Ps. The original code did the same thing.)

========
If you wanted to get the last x number of values from column A, you could use
something like:

Option Explicit
Sub testme04()

Dim ends As Variant
Dim HowMany As Long
Dim LastCell As Range
dim iCtr as long

With sheet11
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
HowMany = .Cells(18, 14).Value
ends = application.transpose(LastCell.Offset(1 - HowMany, 0) _
.Resize(HowMany, 1).Value)
End With

'to prove it works
for ictr = lbound(ends) to ubound(ends)
msgbox ictr & "--" & ends(ictr)
next ictr

End Sub

Kevin O'Neill wrote:

Dim c() As Integer
Dim ends(20) As Integer
For d = Sheet11.Cells(18, 14).Value - 1 To 0 Step -1
ends(d) = Range("A50000").End(xlUp).Row
c() = ends()
Next d 'end stud loop
ReDim Preserve c(Sheet11.Cells(18, 14).Value - 1)

The data in the table is backwards. I assume due to the step -1? Is
there a VBA command to reverse the data in c() ?

Ex. from 1,2,3...to 3,2,1...

Suggestions?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default How to reverse data in an Array

Thanks, ended up using this.

ends(ab) = Range("A50000").End(xlUp).Row
ab = ab + 1
c() = ends()
ReDim Preserve c(Sheet11.Cells(18, 14).Value - 1)

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
Reverse a function to return the array? bc4240 Excel Worksheet Functions 4 July 31st 09 05:25 AM
search an array in reverse (bottom to top) order Trainer_00 Excel Discussion (Misc queries) 5 December 20th 07 10:35 PM
reverse data megsie jack Excel Discussion (Misc queries) 1 September 30th 05 06:00 AM
how to reverse a range/array? peter dmz Excel Worksheet Functions 5 August 11th 05 09:11 PM
DATA VALIDATION IN REVERSE Wayne Excel Discussion (Misc queries) 3 March 22nd 05 12:29 PM


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