Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Copy a range into an array

I have a range ("B3:B23") in worsheet "Ranges" and I need to loop thru this
range and copy the values into an array.

Many Thanks
--
Robert Hill

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Copy a range into an array

hopefully this'll work:

Dim myArray()
Erase myArray 'incase it's already full
myArray =
Application.Transpose(ThisWorkbook.Sheets("Ranges" ).Range("B3:B23"))

Rgds
J


On Mar 23, 2:55 pm, Robert wrote:
I have a range ("B3:B23") in worsheet "Ranges" and I need to loop thru this
range and copy the values into an array.

Many Thanks
--
Robert Hill



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Copy a range into an array

Thank You. Worked great.
--
Robert Hill



"WhytheQ" wrote:

hopefully this'll work:

Dim myArray()
Erase myArray 'incase it's already full
myArray =
Application.Transpose(ThisWorkbook.Sheets("Ranges" ).Range("B3:B23"))

Rgds
J


On Mar 23, 2:55 pm, Robert wrote:
I have a range ("B3:B23") in worsheet "Ranges" and I need to loop thru this
range and copy the values into an array.

Many Thanks
--
Robert Hill




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy a range into an array


public vois CopySelectedItemsOneByOne();
// Get Row Count in Range
int lastRow = (LExcel.ActiveSheet as
Excel.Worksheet).UsedRange.Rows.Count;

//Get Col Count in Range
int lastCol = (LExcel.ActiveSheet as
Excel.Worksheet).UsedRange.Columns.Count;

object value;
//object value2;

Excel.Range excelCell = (Excel.Range)ThisAddIn.ExcelApp.Selection;

object obj = ThisAddIn.ExcelApp.Selection;

if (obj is Excel.Range)
{
Excel.Range selection = (Excel.Range)obj;

//value2 = (selection.Cells[lastRow, lastCol] as Excel.Range);

// Get Address Of Last Cell
string x = (selection.Cells[lastRow, lastCol] as
Excel.Range).Cells.get_Address(false, false,
Microsoft.Office.Interop.Excel.XlReferenceStyle.xl A1, null, null);


// Get Values of all cells
for (int c = 1; c <= lastCol; c++)
{
for (int r = 1; r <= lastRow; r++)
{
value = (selection.Cells[r, c] as Excel.Range).Value2;
if (value != null)
{
MessageBox.Show(value.ToString());
}
}
}


}

------------------------

"Robert" wrote:

Thank You. Worked great.
--
Robert Hill



"WhytheQ" wrote:

hopefully this'll work:

Dim myArray()
Erase myArray 'incase it's already full
myArray =
Application.Transpose(ThisWorkbook.Sheets("Ranges" ).Range("B3:B23"))

Rgds
J


On Mar 23, 2:55 pm, Robert wrote:
I have a range ("B3:B23") in worsheet "Ranges" and I need to loop thru this
range and copy the values into an array.

Many Thanks
--
Robert Hill




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
What is the fastest way to copy a range to a 2D array? equiangular Excel Programming 10 February 12th 07 02:25 PM
copy one array formula to an array range guedj54 Excel Programming 2 October 29th 06 07:38 PM
Read through Range and copy Cell data to Array missleigh[_2_] Excel Programming 1 April 13th 06 12:47 PM
Copy Range and Paste to Array of Sheets bobwilson[_21_] Excel Programming 4 April 6th 06 01:23 PM
How Can I copy all value of the array into the range? sjoo Excel Programming 0 August 8th 03 07:30 AM


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

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"