Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Returning an array in excel

Hi, I'm failrly new to VBA and I wondered if anyone could
help me with this problem.

I am trying to use an array from a worksheet 'Data' to
return a picklist when entering details on another
worksheet. I can get the required picklist to work if I
specify the range (see code below) but the data list is
not static in that the end cell range can be greater or
more than the defined end range cell in my code(A60). How
can I change my code so that the specified range starts at
cell A2 and ends in the last cell where data is input on
the 'Data' worksheet.

The code i'm currently using is:


Sub AddDropDown(Target As Range)
Dim ddbox As DropDown
Dim vaCompany As Variant
Dim i As Integer

vaCompany = Array(Sheets("data").Range("A2:A60"))
With Target
Set ddbox = Sheet3.DropDowns.Add
(.Left, .Top, .Width, .Height)
End With
With ddbox
..OnAction = "Sheet3.EnterCompName"
For i = LBound(vaCompany) To UBound(vaCompany)
..AddItem vaCompany(i)
Next i
End With
End Sub


Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Returning an array in excel

Sub AddDropDown(Target As Range)
Dim ddbox As DropDown
Dim vaCompany As Variant
Dim i As Integer, rng As Range
With Sheets("Data")
Set rng = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
vaCompany = rng.Value
With Target
Set ddbox = Sheet3.DropDowns.Add(.Left, .Top, .Width, .Height)
End With
With ddbox
..OnAction = "Sheet3.EnterCompName"
..List = vaCompany

End With
End Sub


--
Regards,
Tom Ogilvy

"mick" wrote in message
...
Hi, I'm failrly new to VBA and I wondered if anyone could
help me with this problem.

I am trying to use an array from a worksheet 'Data' to
return a picklist when entering details on another
worksheet. I can get the required picklist to work if I
specify the range (see code below) but the data list is
not static in that the end cell range can be greater or
more than the defined end range cell in my code(A60). How
can I change my code so that the specified range starts at
cell A2 and ends in the last cell where data is input on
the 'Data' worksheet.

The code i'm currently using is:


Sub AddDropDown(Target As Range)
Dim ddbox As DropDown
Dim vaCompany As Variant
Dim i As Integer

vaCompany = Array(Sheets("data").Range("A2:A60"))
With Target
Set ddbox = Sheet3.DropDowns.Add
(.Left, .Top, .Width, .Height)
End With
With ddbox
.OnAction = "Sheet3.EnterCompName"
For i = LBound(vaCompany) To UBound(vaCompany)
.AddItem vaCompany(i)
Next i
End With
End Sub


Thanks for your help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Returning an array in excel

Thanks Tom, your help is much appreciated. I can see where
I was going wrong.

Regards

Mick.
-----Original Message-----
Sub AddDropDown(Target As Range)
Dim ddbox As DropDown
Dim vaCompany As Variant
Dim i As Integer, rng As Range
With Sheets("Data")
Set rng = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
vaCompany = rng.Value
With Target
Set ddbox = Sheet3.DropDowns.Add

(.Left, .Top, .Width, .Height)
End With
With ddbox
..OnAction = "Sheet3.EnterCompName"
..List = vaCompany

End With
End Sub


--
Regards,
Tom Ogilvy

"mick" wrote in

message
...
Hi, I'm failrly new to VBA and I wondered if anyone

could
help me with this problem.

I am trying to use an array from a worksheet 'Data' to
return a picklist when entering details on another
worksheet. I can get the required picklist to work if I
specify the range (see code below) but the data list is
not static in that the end cell range can be greater or
more than the defined end range cell in my code(A60).

How
can I change my code so that the specified range starts

at
cell A2 and ends in the last cell where data is input on
the 'Data' worksheet.

The code i'm currently using is:


Sub AddDropDown(Target As Range)
Dim ddbox As DropDown
Dim vaCompany As Variant
Dim i As Integer

vaCompany = Array(Sheets("data").Range("A2:A60"))
With Target
Set ddbox = Sheet3.DropDowns.Add
(.Left, .Top, .Width, .Height)
End With
With ddbox
.OnAction = "Sheet3.EnterCompName"
For i = LBound(vaCompany) To UBound(vaCompany)
.AddItem vaCompany(i)
Next i
End With
End Sub


Thanks for your help.



.

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
Returning an array of unique values? Blue Max Excel Worksheet Functions 10 January 16th 08 02:51 AM
Array formula returning the cumulative sum vsoler Excel Worksheet Functions 15 June 15th 07 10:54 PM
Returning an address from an array wienmichael Excel Discussion (Misc queries) 6 May 2nd 07 02:53 AM
Returning an array from a UDF to a column range Ron Davis Excel Programming 1 October 31st 03 01:12 AM
returning an array from a custom function Ron Davis Excel Programming 2 September 15th 03 11:02 AM


All times are GMT +1. The time now is 12:15 PM.

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

About Us

"It's about Microsoft Excel"