Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Fill Array not working

Hi,

The following array code gives me an error message Run time error 1004
"Application defined or object defined error" How do I fix? Thanks -
Dean

MyArray = Worksheets("TEST").Range(Range("A2"),
Range("A100").End(xlUp))

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Fill Array not working


Dim MyArray As Variant
MyArray = Worksheets("TEST").Range("A2", Range("A100").End(xlUp)).Value
MsgBox LBound(MyArray) & vbCr & UBound(MyArray)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




wrote in message
Hi,
The following array code gives me an error message Run time error 1004
"Application defined or object defined error" How do I fix? Thanks -
Dean

MyArray = Worksheets("TEST").Range(Range("A2"),
Range("A100").End(xlUp))

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Fill Array not working

Dean,
Depending on the location of this code, the unqualified Range objects may
refer to either the active sheet (if in a standard module) or the sheet that
holds this code, neither of which MAY be Worksheets("TEST").
It is always more clear for yourself (and others, later) and VBA to qualify
them. Assuming you mean:

With Worksheets("TEST")
MyArray = .Range("A2",.Range("A100").End(xlUp))
End With
'Notice the "." before the ranges

NickHK

wrote in message
oups.com...
Hi,

The following array code gives me an error message Run time error 1004
"Application defined or object defined error" How do I fix? Thanks -
Dean

MyArray = Worksheets("TEST").Range(Range("A2"),
Range("A100").End(xlUp))



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Fill Array not working

On May 3, 2:26 pm, "NickHK" wrote:
Dean,
Depending on the location of this code, the unqualified Range objects may
refer to either the active sheet (if in a standard module) or the sheet that
holds this code, neither of which MAY be Worksheets("TEST").
It is always more clear for yourself (and others, later) and VBA to qualify
them. Assuming you mean:

With Worksheets("TEST")
MyArray = .Range("A2",.Range("A100").End(xlUp))
End With
'Notice the "." before the ranges

NickHK

wrote in message

oups.com...



Hi,


The following array code gives me an error message Run time error 1004
"Application defined or object defined error" How do I fix? Thanks -
Dean


MyArray = Worksheets("TEST").Range(Range("A2"),
Range("A100").End(xlUp))- Hide quoted text -


- Show quoted text -


Hi Nick,
I have the following code. When I hard code the array with the values
the code works. When I try to make the array dynamic nothing
populates the array. Do I need to Redim the array? Is it a Ubound/
Lbound issue? I apologise as we have been over this a few times but I
cannot seem to get this to work. Dynamic arrays are proving difficult
for me to get. Please advise. Thanks for your patience.

Public Sub CreateCSV()

Dim Sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim MyArray As Variant

' MyArray = Array("23000-7000", "23000-7300", "23000-7040") THIS
WORKS

With Worksheets("TEST")
MyArray = .Range("A2", .Range("A100").End(xlUp))
End With

On Error Resume Next
If Len(ThisWorkbook.Worksheets.Item("CSV").Name) = 0 Then
On Error GoTo 0
Application.ScreenUpdating = False
Set DestSh = ThisWorkbook.Worksheets.Add
DestSh.Name = "CSV"
For Each Sh In Sheets(MyArray())
Last = LastRow(DestSh)

With Sh.Range("A6:Q281")
DestSh.Cells(Last + 1, "A").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

Next
DestSh.Cells(1).Select
Application.ScreenUpdating = True
Else
Set DestSh = ThisWorkbook.Worksheets("CSV")
For Each Sh In Sheets(MyArray)
Last = LastRow(DestSh)

With Sh.Range("A6:Q213")
DestSh.Cells(Last + 1, "A").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

Next
DestSh.Cells(1).Select
Application.ScreenUpdating = True

End If

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Fill Array not working

Dean,
When you fill an array from a worksheet, you will get a 2-D array (even if
you only select a single column/row), not a 1-D array as you do when using
Array().

Check the:
Ubound(MyArray,1)
Ubound(MyArray,2)

NickHK

wrote in message
oups.com...
On May 3, 2:26 pm, "NickHK" wrote:
Dean,
Depending on the location of this code, the unqualified Range objects

may
refer to either the active sheet (if in a standard module) or the sheet

that
holds this code, neither of which MAY be Worksheets("TEST").
It is always more clear for yourself (and others, later) and VBA to

qualify
them. Assuming you mean:

With Worksheets("TEST")
MyArray = .Range("A2",.Range("A100").End(xlUp))
End With
'Notice the "." before the ranges

NickHK

wrote in message

oups.com...



Hi,


The following array code gives me an error message Run time error 1004
"Application defined or object defined error" How do I fix? Thanks -
Dean


MyArray = Worksheets("TEST").Range(Range("A2"),
Range("A100").End(xlUp))- Hide quoted text -


- Show quoted text -


Hi Nick,
I have the following code. When I hard code the array with the values
the code works. When I try to make the array dynamic nothing
populates the array. Do I need to Redim the array? Is it a Ubound/
Lbound issue? I apologise as we have been over this a few times but I
cannot seem to get this to work. Dynamic arrays are proving difficult
for me to get. Please advise. Thanks for your patience.

Public Sub CreateCSV()

Dim Sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim MyArray As Variant

' MyArray = Array("23000-7000", "23000-7300", "23000-7040") THIS
WORKS

With Worksheets("TEST")
MyArray = .Range("A2", .Range("A100").End(xlUp))
End With

On Error Resume Next
If Len(ThisWorkbook.Worksheets.Item("CSV").Name) = 0 Then
On Error GoTo 0
Application.ScreenUpdating = False
Set DestSh = ThisWorkbook.Worksheets.Add
DestSh.Name = "CSV"
For Each Sh In Sheets(MyArray())
Last = LastRow(DestSh)

With Sh.Range("A6:Q281")
DestSh.Cells(Last + 1, "A").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

Next
DestSh.Cells(1).Select
Application.ScreenUpdating = True
Else
Set DestSh = ThisWorkbook.Worksheets("CSV")
For Each Sh In Sheets(MyArray)
Last = LastRow(DestSh)

With Sh.Range("A6:Q213")
DestSh.Cells(Last + 1, "A").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

Next
DestSh.Cells(1).Select
Application.ScreenUpdating = True

End If

End Sub





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
Fill series not working as expected Lauren Excel Discussion (Misc queries) 1 February 16th 10 07:11 PM
Day of week Fill down column not working Minion Excel Worksheet Functions 4 April 7th 09 04:27 AM
how do i fill an array? tia JasonK[_2_] Excel Programming 7 September 19th 06 07:31 PM
fill array [email protected][_2_] Excel Programming 7 March 20th 06 01:01 PM
fill down array to last available row [email protected] Excel Worksheet Functions 10 May 19th 05 10:52 PM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"