Writing multicolumn array data to a worksheet range
Thanks for the reply.
No error message appears. I did re locate the unload command as you
suggested but it made no difference.
I tried using a test array that I created as follows:
testArray = Array (1,2,3,4,5,6,7,8)
The data in the test array does get written into the worksheet range the way
I want using my code so I believe my problem has to do with the way i have
created my 2D array called CustArray.
"RB Smissaert" wrote:
Any error message?
Try putting Unload userform1 at the very end of that Sub
RBS
"BobbyC163" wrote in message
...
have an Excel worksheet (called MyWorksheet) where I am trying to select a
customer name and address from a list of all customers located on another
worksheet (CustomerWorksheet). I am using a multicolumn listbox on a
userform
to select the customer data. Once selected, I want to capture the customer
data in a multicolumn array and then write the customer data to a
worksheet
range in MyWorksheet.
The code I have written seems to be able to capture the selected customer
data (all columns) in an array but it will not write the data to the range
in
the MyWorksheet. Any help would be greatly appreciated.
Thanks
Private Sub cmdOkay_Click()
Dim i As Long, j As Long
Dim lRows As Long, lCols As Long
Dim CustArray() As Variant
lRows = ListBox1.ListCount - 1
lCols = ListBox1.ColumnCount - 1
'Fill array with data of selected customer
For i = 1 To lRows
If ListBox1.Selected(i) Then
For j = 0 To lCols
ReDim CustArray(lRows, lCols)
CustArray(1, j) = ListBox1.List(i, j)
Next j
End If
Next i
Unload userform1
'Write array data to range on worksheet
With Worksheets("MyWorksheet").Range("CustomerData")
.ClearContents
.Value = CustArray
End With
End Sub
|