Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get array from multi-selection range

Status
Not open for further replies.

bartrein

Programmer
Sep 22, 2008
49
EU
Hi

I have got a macro which basically does the following :

- finds and selects all the numbers in one column using special cells (column contains numbers and some text comments)

- copies all those numbers and corresponding codes located in another column(Offset(0, -3)to another sheet

-creates a variant array : vaUpload = Range("a1:n" & iLastRow).Value from copied&pasted data

What i would like to do is to bypass that copy and paste step and put all the numbers and codes directly into my array after they get selected.
The only quick way of doing this i know (vArray = Range("a1:n" & iLastRow).Value) does not work on the multiple selected cells - the example range adress of selected cells would be somthing like " $b$1:$b$2,$b$7,$b$9:$b$15 "

Does anyone know how to put this into array in a quick way?
Hope it makes sense - i would be very grateful for all suggestions.

Thanks
-----------------------------------------------------------
the code :

'select numeric constants from my column
Selection.SpecialCells(xlCellTypeConstants, 1).Select

'get the address of selected cells
'how to get this into my array without copy&paste?
rngCodes = Selection.Offset(0, -3).Address
rngPrices = Selection.Address
'

'go to upload sheet
With Sheets("Upload")
.Visible = True
.Select
End With

'clear prv run
Cells.ClearContents

'copy codes
Sheets(sMySheet).Range(rngCodes).Copy
Range("a2").Select
ActiveSheet.Paste

'copy prices
Sheets(sMySheet).Range(rngPrices).Copy
Range("f2").Select
ActiveSheet.Paste

'find last record
iLastRow = Range("A65536").End(xlUp).Row

'create an array
vaUpload = Range("a1:n" & iLastRow).Value
 
What about doing it the slow way to bypass the copy/paste step ... copying one cell at a time into your array? ( see For Each help )

Cheers, Glenn.

Beauty is in the eye of the beerholder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top