Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set values in an Array

Is there a way to load an array with data from a worksheet? Here is
the code I have.

ActiveSheet.ListObjects("List12559").Range.AutoFil ter Field:=1,
Criteria1:= _
Array("103", "113", "123", "213", "220", "227", "231", "235",
"290", "500", _
"540", "900"), Operator:=xlFilterValues

These values are in A1-A12. I am hoping to make this more dynamic so
when I add a criteria I can just add it to the sheet and not to the
sheet and the VBA macro.

Any help woudl be appreciated,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 561
Default Set values in an Array

Try the hereunder code.
The 2 Message Boxes prove that the 12 values are kept, each' in the
respective cell.
=====================
Sub Fill_One_Dimensional_Array()
Dim Rng As Range
Arr = Range("A1:A12")
MsgBox Arr(3, 1)
MsgBox Arr(5, 1)
End Sub
================
To make the list dynamically - check for the last filled cell in column "A":
LR = Cells(Rows.Count ,1).End(xlUP).Row
then use LR in the Array filling command:
Arr = Range("A1:A" & LR)
Micky


"jlclyde" wrote:

Is there a way to load an array with data from a worksheet? Here is
the code I have.

ActiveSheet.ListObjects("List12559").Range.AutoFil ter Field:=1,
Criteria1:= _
Array("103", "113", "123", "213", "220", "227", "231", "235",
"290", "500", _
"540", "900"), Operator:=xlFilterValues

These values are in A1-A12. I am hoping to make this more dynamic so
when I add a criteria I can just add it to the sheet and not to the
sheet and the VBA macro.

Any help woudl be appreciated,
Jay
.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Set values in an Array

I didn't test this, so it may not work...

Dim myArr as variant

with worksheets("nameofsheetwithlist")
myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with

'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
criterial:=myarr, operator:=xlfiltervalues



jlclyde wrote:

Is there a way to load an array with data from a worksheet? Here is
the code I have.

ActiveSheet.ListObjects("List12559").Range.AutoFil ter Field:=1,
Criteria1:= _
Array("103", "113", "123", "213", "220", "227", "231", "235",
"290", "500", _
"540", "900"), Operator:=xlFilterValues

These values are in A1-A12. I am hoping to make this more dynamic so
when I add a criteria I can just add it to the sheet and not to the
sheet and the VBA macro.

Any help woudl be appreciated,
Jay


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set values in an Array

On Dec 7, 12:01*pm, Dave Peterson wrote:
I didn't test this, so it may not work...

Dim myArr as variant

with worksheets("nameofsheetwithlist")
* myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with

'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
* *criterial:=myarr, operator:=xlfiltervalues

Dave, This did not work. I get subscript out of range. Any other
thoughts? I am sure this is possible and I have been playign with it
all morning to no avail.
Thanks,
Jay



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set values in an Array

On Dec 7, 12:51*pm, jlclyde wrote:
On Dec 7, 12:01*pm, Dave Peterson wrote: I didn't test this, so it may not work...

Dim myArr as variant


with worksheets("nameofsheetwithlist")
* myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with


'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
* *criterial:=myarr, operator:=xlfiltervalues


Dave, This did not work. *I get subscript out of range. *Any other
thoughts? *I am sure this is possible and I have been playign with it
all morning to no avail.
Thanks,
Jay


Dave,
I was wrong.....Your code works fine when I am pointing at the right
list. That is why I was gettign the error.

Thanks for the help,
Jay


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set values in an Array

On Dec 7, 1:36*pm, jlclyde wrote:
On Dec 7, 12:51*pm, jlclyde wrote:





On Dec 7, 12:01*pm, Dave Peterson wrote: I didn't test this, so it may not work...


Dim myArr as variant


with worksheets("nameofsheetwithlist")
* myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with


'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
* *criterial:=myarr, operator:=xlfiltervalues


Dave, This did not work. *I get subscript out of range. *Any other
thoughts? *I am sure this is possible and I have been playign with it
all morning to no avail.
Thanks,
Jay


Dave,
I was wrong.....Your code works fine when I am pointing at the right
list. *That is why I was gettign the error.

Thanks for the help,
Jay- Hide quoted text -

- Show quoted text -


Dave,
I was wrong again....Here is the code I ahve and it is sorting th
ecorrect list it just does not leave nay value on the screen. I am
not sure what is goign on here is my code.
Jay
Sub Macro3()
Dim MyArray As Variant
With Sheet4
MyArray = .Range("A5", .Cells(5, .Range("A5").End
(xlToRight).Column)).Value
End With

Sheet5.ListObjects(1).Range.AutoFilter Field:=1, Criteria1:= _
MyArray, Operator:=xlFilterValues
End Sub
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Set values in an Array

I think the problem is with this statement:

MyArray = .Range("A5", .Cells(5, .Range("A5").End(xlToRight).Column)).Value

This .cells(5,.range("A5").end(xltoright).column will result in a number. And
that isn't gonna be valid argument inside Range().

So maybe...

MyArray = .Range("A5:A" & .Cells(5, .Range("A5").End(xlToRight).Column)).Value
or
MyArray = .Range("A5", .Cells(5, .Range("A5").End(xlToRight))).Value

I like starting at the far right (or bottom) and working the way left (or up):

MyArray = .Range("A5", .Cells(5,.columns.count).end(xltoleft)).Value

But I thought your list was in A1:A12--not horizontal????

(Still untested--in either direction.)

jlclyde wrote:

On Dec 7, 1:36 pm, jlclyde wrote:
On Dec 7, 12:51 pm, jlclyde wrote:





On Dec 7, 12:01 pm, Dave Peterson wrote: I didn't test this, so it may not work...


Dim myArr as variant


with worksheets("nameofsheetwithlist")
myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with


'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
criterial:=myarr, operator:=xlfiltervalues


Dave, This did not work. I get subscript out of range. Any other
thoughts? I am sure this is possible and I have been playign with it
all morning to no avail.
Thanks,
Jay


Dave,
I was wrong.....Your code works fine when I am pointing at the right
list. That is why I was gettign the error.

Thanks for the help,
Jay- Hide quoted text -

- Show quoted text -


Dave,
I was wrong again....Here is the code I ahve and it is sorting th
ecorrect list it just does not leave nay value on the screen. I am
not sure what is goign on here is my code.
Jay
Sub Macro3()
Dim MyArray As Variant
With Sheet4
MyArray = .Range("A5", .Cells(5, .Range("A5").End
(xlToRight).Column)).Value
End With

Sheet5.ListObjects(1).Range.AutoFilter Field:=1, Criteria1:= _
MyArray, Operator:=xlFilterValues
End Sub


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set values in an Array

On Dec 7, 2:50*pm, Dave Peterson wrote:
I think the problem is with this statement:

*MyArray = .Range("A5", .Cells(5, .Range("A5").End(xlToRight).Column)).Value

This .cells(5,.range("A5").end(xltoright).column will result in a number. *And
that isn't gonna be valid argument inside Range().

So maybe...

*MyArray = .Range("A5:A" & .Cells(5, .Range("A5").End(xlToRight).Column)).Value
or
*MyArray = .Range("A5", .Cells(5, .Range("A5").End(xlToRight))).Value

I like starting at the far right (or bottom) and working the way left (or up):

*MyArray = .Range("A5", .Cells(5,.columns.count).end(xltoleft)).Value

But I thought your list was in A1:A12--not horizontal????

(Still untested--in either direction.)





jlclyde wrote:

On Dec 7, 1:36 pm, jlclyde wrote:
On Dec 7, 12:51 pm, jlclyde wrote:


On Dec 7, 12:01 pm, Dave Peterson wrote: I didn't test this, so it may not work...


Dim myArr as variant


with worksheets("nameofsheetwithlist")
* myarr = .range("a1",.cells(.rows.count,"A").end(xlup)).val ue
end with


'then your code
activesheet.listobjects("list12559").range.autofil ter field:=1, _
* *criterial:=myarr, operator:=xlfiltervalues


Dave, This did not work. *I get subscript out of range. *Any other
thoughts? *I am sure this is possible and I have been playign with it
all morning to no avail.
Thanks,
Jay


Dave,
I was wrong.....Your code works fine when I am pointing at the right
list. *That is why I was gettign the error.


Thanks for the help,
Jay- Hide quoted text -


- Show quoted text -


Dave,
I was wrong again....Here is the code I ahve and it is sorting th
ecorrect list it just does not leave nay value on the screen. *I am
not sure what is goign on here is my code.
Jay
Sub Macro3()
* * Dim MyArray As Variant
* * With Sheet4
* * * * MyArray = .Range("A5", .Cells(5, .Range("A5").End
(xlToRight).Column)).Value
* * End With


* * Sheet5.ListObjects(1).Range.AutoFilter Field:=1, Criteria1:= _
* * * * MyArray, Operator:=xlFilterValues
End Sub


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Dave,
If you get a moment to test it does not show any of the values in the
array. I had the data originally going down, but then I changed then
to be column headings on a seperate list. Sorry for any confusion.

Thanks,
Jay
  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Set values in an Array

I started up xl2007.

I put some data into c7:J27.
I used Insert|Table to create the table (with headers). It defaulted to a name
of Table1.

I added some entries in C5:E5 that matched some of the values in the first
column of my table.

Then I ran this macro:

Option Explicit
Sub testme()

Dim myArr As Variant

With Worksheets("sheet1")

myArr = .Range("a5", .Cells(5, .Columns.Count).End(xlToLeft)).Value

.ListObjects("Table1").Range.AutoFilter Field:=1, _
Criteria1:=myArr, Operator:=xlFilterValues

End With

End Sub

If this doesn't help, please give more details--where the data is, where the
table is, and where that criteria is.






jlclyde wrote:

<<snipped
Dave,
If you get a moment to test it does not show any of the values in the
array. I had the data originally going down, but then I changed then
to be column headings on a seperate list. Sorry for any confusion.

Thanks,
Jay


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Set values in an Array

Ps. Ron de Bruin has lots of vba samples for working with lists and tables
he
http://www.rondebruin.nl/tips.htm
look for Table

jlclyde wrote:
<<snipped
--

Dave Peterson
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
Looking Up Two Values in an Array Mike M[_2_] Excel Worksheet Functions 6 January 6th 09 05:34 AM
looking a value in an array text values Francois Excel Worksheet Functions 2 September 17th 08 02:55 AM
Array: Counting multiple values within array Trilux_nogo Excel Worksheet Functions 4 April 16th 07 03:12 AM
To get values into an array Darren1o1 Excel Worksheet Functions 7 April 14th 06 11:14 PM
Use array to return array of values Brad Excel Worksheet Functions 2 March 30th 06 05:58 PM


All times are GMT +1. The time now is 08:33 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"