Copy a range into an array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
hopefully this'll work:

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

Rgds
J
 
Thank You. Worked great.
--
Robert Hill



WhytheQ said:
hopefully this'll work:

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

Rgds
J
 
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.xlA1, 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());
}
}
}


}

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top