PC Review


Reply
Thread Tools Rate Thread

Capture a group of cells as an array

 
 
Bythsx-Addagio
Guest
Posts: n/a
 
      29th Oct 2008
Hello,
I have a worksheet with data presented in repeating clusters which I would
like to rearrange into a single row. There are 5 items spread across 2
colums and 5 rows. Would it make sense to assign the cell values to an
array, then print that array to a single row and repeat for as many clusters?
Code is below:
Thanks in advance!

Sub FormatRatings()
Dim RateData As Variant
Dim AsOf As Date
Dim a As Long, b As Long, c As Long, d As Long, e As Long, x As Long
'a through e are cell row references
'x = Load Sheet row
'Starting reference
a = 12
b = 13
c = 14
d = 15
c = 16
x = 2

For i = 1 To 30 Step 1
'Gather Data
Sheets(2).Select
RateData = Array(AsOf, Cells(a, 1).Value, Cells(b, 2).Value, Cells(c,
2).Value, Cells(d, 2).Value, Cells(e, 2).Value)
'Print Data
Sheets(1).Select
Range(Cells(x, 1), Cells(x, 6)).Value = RateData

'Increment reference locations
a = a + 5
b = b + 5
c = c + 5
d = d + 5
e = e + 5
x = x + 1

Next i
End Sub

 
Reply With Quote
 
 
 
 
Sheeloo
Guest
Posts: n/a
 
      29th Oct 2008
Anything which reduces I/O helps.

But if the whole procedure takes seconds then trying to optimize may not be
worth the effort...

One can also argue that if speed is critical then VBA is not a good
choice... :-)

Declare the Array in the beginning and not create one like you do with each
iteration.
Assign each element in a loop...


"Bythsx-Addagio" wrote:

> Hello,
> I have a worksheet with data presented in repeating clusters which I would
> like to rearrange into a single row. There are 5 items spread across 2
> colums and 5 rows. Would it make sense to assign the cell values to an
> array, then print that array to a single row and repeat for as many clusters?
> Code is below:
> Thanks in advance!
>
> Sub FormatRatings()
> Dim RateData As Variant
> Dim AsOf As Date
> Dim a As Long, b As Long, c As Long, d As Long, e As Long, x As Long
> 'a through e are cell row references
> 'x = Load Sheet row
> 'Starting reference
> a = 12
> b = 13
> c = 14
> d = 15
> c = 16
> x = 2
>
> For i = 1 To 30 Step 1
> 'Gather Data
> Sheets(2).Select
> RateData = Array(AsOf, Cells(a, 1).Value, Cells(b, 2).Value, Cells(c,
> 2).Value, Cells(d, 2).Value, Cells(e, 2).Value)
> 'Print Data
> Sheets(1).Select
> Range(Cells(x, 1), Cells(x, 6)).Value = RateData
>
> 'Increment reference locations
> a = a + 5
> b = b + 5
> c = c + 5
> d = d + 5
> e = e + 5
> x = x + 1
>
> Next i
> End Sub
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel screen capture to capture cells and row and column headings jayray Microsoft Excel Misc 5 2nd Nov 2007 11:01 PM
combining cells and array from different sheets into an array to pass to IRR() danyates77@yahoo.com Microsoft Excel Misc 3 11th Sep 2006 07:17 AM
Screen capture to byte array ozzythewizard Microsoft Dot NET Compact Framework 1 18th Jul 2006 01:30 PM
Capture Screen to Byte Array =?Utf-8?B?S2VpdGg=?= Microsoft Dot NET Compact Framework 5 17th Sep 2005 10:07 PM
How to find values for a group of cells based on another group of cells Mike Microsoft Excel Worksheet Functions 0 9th Sep 2003 08:34 PM


Features
 

Advertising
 

Newsgroups
 


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