Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default creating a range by searching another worksheet

I am trying to build a range by having a procedure go through a range. I
have a range of markets. The range is column A. In column A at the very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will be ("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get the
procedure to go throught the range. Any help on how to do this is greatly
appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default creating a range by searching another worksheet

Hi
try the following (not fully tested)
sub test_rng
dim ar_values as variant
Dim RowNdx As Long
Dim LastRow As Long
dim i

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
redim ar_values(1 to lastrow)
i=0

For RowNdx = 1 To lastrow
with Cells(RowNdx, "A")
if left(.value,1)="M" then
i=i+1
ar_values(i)=left(.value,2)
end if
end with
Next RowNdx
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

"Rich Cooper" schrieb im Newsbeitrag
...
I am trying to build a range by having a procedure go through a

range. I
have a range of markets. The range is column A. In column A at the

very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will be

("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get the
procedure to go throught the range. Any help on how to do this is

greatly
appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default creating a range by searching another worksheet

Frank
Thats helping alot but i am running into some problems. Hopefully you can
help. I want the row it starts at to be M1P1 and in the array i want it tp
only count M1 once. SO the final array should look like this if i only have
a list that goes up to M4P4. ar_values("m1","m2","m3"m4") Hope that makes
it a little clear what i am trying to do.

"Frank Kabel" wrote in message
...
Hi
try the following (not fully tested)
sub test_rng
dim ar_values as variant
Dim RowNdx As Long
Dim LastRow As Long
dim i

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
redim ar_values(1 to lastrow)
i=0

For RowNdx = 1 To lastrow
with Cells(RowNdx, "A")
if left(.value,1)="M" then
i=i+1
ar_values(i)=left(.value,2)
end if
end with
Next RowNdx
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

"Rich Cooper" schrieb im Newsbeitrag
...
I am trying to build a range by having a procedure go through a

range. I
have a range of markets. The range is column A. In column A at the

very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will be

("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get the
procedure to go throught the range. Any help on how to do this is

greatly
appreciated.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default creating a range by searching another worksheet

Hi
some questions
- is your data sorted
- does it start in a fixed row

--
Regards
Frank Kabel
Frankfurt, Germany

"Rich Cooper" schrieb im Newsbeitrag
...
Frank
Thats helping alot but i am running into some problems. Hopefully

you can
help. I want the row it starts at to be M1P1 and in the array i want

it tp
only count M1 once. SO the final array should look like this if i

only have
a list that goes up to M4P4. ar_values("m1","m2","m3"m4") Hope that

makes
it a little clear what i am trying to do.

"Frank Kabel" wrote in message
...
Hi
try the following (not fully tested)
sub test_rng
dim ar_values as variant
Dim RowNdx As Long
Dim LastRow As Long
dim i

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
redim ar_values(1 to lastrow)
i=0

For RowNdx = 1 To lastrow
with Cells(RowNdx, "A")
if left(.value,1)="M" then
i=i+1
ar_values(i)=left(.value,2)
end if
end with
Next RowNdx
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

"Rich Cooper" schrieb im Newsbeitrag
...
I am trying to build a range by having a procedure go through a

range. I
have a range of markets. The range is column A. In column A at

the
very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will

be
("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get

the
procedure to go throught the range. Any help on how to do this

is
greatly
appreciated.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default creating a range by searching another worksheet

You can also do this using a collection as illustrated by John Walkenbach:

http://j-walk.com/ss/excel/tips/tip47.htm
Filling a ListBox With Unique Items

While the sample code fills a listbox, that is only a small part of the code
at the bottom. Most of the code is focused on getting a unique list (and
then sorting it

Do you mean you want it to search down the column until it finds the first
instance of M1P1 and then start there?

--
Regards,
Tom Ogilvy

"Rich Cooper" wrote in message
...
Frank
Thats helping alot but i am running into some problems. Hopefully you can
help. I want the row it starts at to be M1P1 and in the array i want it

tp
only count M1 once. SO the final array should look like this if i only

have
a list that goes up to M4P4. ar_values("m1","m2","m3"m4") Hope that

makes
it a little clear what i am trying to do.

"Frank Kabel" wrote in message
...
Hi
try the following (not fully tested)
sub test_rng
dim ar_values as variant
Dim RowNdx As Long
Dim LastRow As Long
dim i

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
redim ar_values(1 to lastrow)
i=0

For RowNdx = 1 To lastrow
with Cells(RowNdx, "A")
if left(.value,1)="M" then
i=i+1
ar_values(i)=left(.value,2)
end if
end with
Next RowNdx
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

"Rich Cooper" schrieb im Newsbeitrag
...
I am trying to build a range by having a procedure go through a

range. I
have a range of markets. The range is column A. In column A at the

very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will be

("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get the
procedure to go throught the range. Any help on how to do this is

greatly
appreciated.









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default creating a range by searching another worksheet

Sub Tester1()
Dim varr() As String
Dim bUnique As Boolean, sStr As String
Dim cell As Range, rng As Range
Dim i As Long, idex As Long
ReDim varr(0 To 0)
Set rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
idex = 0
For Each cell In rng
sStr = Left(cell.Value, 2)
bUnique = True
For i = LBound(varr) To UBound(varr)
If UCase(sStr) = UCase(varr(i)) Then
bUnique = False
Exit For
End If
Next
If bUnique Then
varr(idex) = sStr
idex = idex + 1
ReDim Preserve varr(0 To idex)
End If
Next
ReDim Preserve varr(0 To idex - 1)
For i = LBound(varr) To UBound(varr)
Debug.Print i, varr(i)
Next

End Sub


You can also do this using a collection as illustrated by John Walkenbach:

http://j-walk.com/ss/excel/tips/tip47.htm
Filling a ListBox With Unique Items

While the sample code fills a listbox, that is only a small part of the code
at the bottom. Most of the code is focused on getting a unique list (and
then sorting it - you can leave that part of the code or keep it according
to your needs).

--
Regards,
Tom Ogilvy




"Rich Cooper" wrote in message
...
I am trying to build a range by having a procedure go through a range. I
have a range of markets. The range is column A. In column A at the very
top you have some summary information then you have M1P1,
M1p2...M2p2...M3p5... I am trying to create an array that will be ("m1",
"m2", "m3"...) but i am having trouble doing this. I can't get the
procedure to go throught the range. Any help on how to do this is greatly
appreciated.




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
SEARCHING RANGE Mickey Mouse[_3_] Excel Discussion (Misc queries) 4 April 12th 08 05:19 AM
searching a range for a sum... chickenshed_bob Excel Worksheet Functions 4 March 30th 06 08:49 PM
3d range searching thephoenix12 Excel Discussion (Misc queries) 0 June 15th 05 06:18 PM
Searching a list with repeat entries and creating a sum Brian Connolly Excel Discussion (Misc queries) 1 February 3rd 05 09:41 PM
searching a range Rich Cooper Excel Programming 1 May 21st 04 04:36 PM


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