PDA

View Full Version : Populate (string) array from sheet



Dimitris254
05-02-2016, 05:59 AM
Hi all,

i'm trying to populate an array from a sheet named "arrays". All arrays are string but for one (which is integer). All the columns have headers and all rows are filled with data.



Option Explicit
Option Base 1

Sub populate()' populate "countries" array

Dim lastrow As Integer
Dim colheader As Integer
Dim countries() As String

' find column by header name
colheader = Worksheets("arrays").Cells.Find(What:="countries", SearchDirection:=xlNext, SearchOrder:=xlByColumns).Column

' find the last non-empty row of this column
lastrow = Worksheets("arrays").Cells(1048576, colheader).End(xlUp).Row

' put all the data of this column in "countries" array
countries = Worksheets("arrays").Range(Cells(2, colheader), Cells(lastrow, colheader))

' check: write the array in "test" sheet
Worksheets("test").Cell(1, 1) = countries

End Sub

I get the following error when i try to pass the range to the array (at countries = ...) :

Run-time error '1004':

Application-defined or object-defined error

Kenneth Hobs
05-02-2016, 06:17 AM
Duplicate post: http://www.mrexcel.com/forum/excel-questions/938662-populate-string-array-sheet.html