ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can I see if an array contain a certain variable? (https://www.excelbanter.com/excel-programming/317006-how-can-i-see-if-array-contain-certain-variable.html)

Ronaldo[_2_]

how can I see if an array contain a certain variable?
 
Hi,

At least do I belive I should use arrays to solve it, but did sleep during
the array part of the course:-)

In an Worksheet_Deactivate event, I want to compare if the Target range is
into one of my known sheets or if it is an unknown sheet. This will make me
know if Target is another workbook, since there will be no more sheets in my
workbook. I thought of running a loop through my array with 13 woorksheets
and see if the "ActiveWorksheet" is there.

I have started to give name the arrays like:

shtArray(0) = Sheet1.Name
shtArray(1) = Sheet2.Name
:
and thought of running a Loop like:
"If ActiveSheet.Name < shtArray" Then

I has been thinking about using woorkbook_deactivate event, but can't find
out how i can get the Target range and continue with my code in a right
way.

Better ways to solve it are of course welcome, but maybe this give me a
reason to learn arrays once and for all:-)


- Regards -



Frank Kabel

how can I see if an array contain a certain variable?
 
Hi
but why do you want to check this?. If you only want to make sure that
it is not the same workbook why not compare the workbook objects?

--
Regards
Frank Kabel
Frankfurt, Germany

"Ronaldo" schrieb im Newsbeitrag
...
Hi,

At least do I belive I should use arrays to solve it, but did sleep

during
the array part of the course:-)

In an Worksheet_Deactivate event, I want to compare if the Target

range is
into one of my known sheets or if it is an unknown sheet. This will

make me
know if Target is another workbook, since there will be no more

sheets in my
workbook. I thought of running a loop through my array with 13

woorksheets
and see if the "ActiveWorksheet" is there.

I have started to give name the arrays like:

shtArray(0) = Sheet1.Name
shtArray(1) = Sheet2.Name
:
and thought of running a Loop like:
"If ActiveSheet.Name < shtArray" Then

I has been thinking about using woorkbook_deactivate event, but can't

find
out how i can get the Target range and continue with my code in a

right
way.

Better ways to solve it are of course welcome, but maybe this give me

a
reason to learn arrays once and for all:-)


- Regards -




Bob Phillips[_6_]

how can I see if an array contain a certain variable?
 
You've lost me mate. What is the Target Range in this instance?

If you just wasn't to see if a worksheet contains a specific worksheet,
there are easier ways.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ronaldo" wrote in message
...
Hi,

At least do I belive I should use arrays to solve it, but did sleep during
the array part of the course:-)

In an Worksheet_Deactivate event, I want to compare if the Target range is
into one of my known sheets or if it is an unknown sheet. This will make

me
know if Target is another workbook, since there will be no more sheets in

my
workbook. I thought of running a loop through my array with 13 woorksheets
and see if the "ActiveWorksheet" is there.

I have started to give name the arrays like:

shtArray(0) = Sheet1.Name
shtArray(1) = Sheet2.Name
:
and thought of running a Loop like:
"If ActiveSheet.Name < shtArray" Then

I has been thinking about using woorkbook_deactivate event, but can't find
out how i can get the Target range and continue with my code in a right
way.

Better ways to solve it are of course welcome, but maybe this give me a
reason to learn arrays once and for all:-)


- Regards -





Alan Beban[_2_]

how can I see if an array contain a certain variable?
 
Ronaldo wrote:
Hi,

At least do I belive I should use arrays to solve it, but did sleep during
the array part of the course:-)

In an Worksheet_Deactivate event, I want to compare if the Target range is
into one of my known sheets or if it is an unknown sheet. This will make me
know if Target is another workbook, since there will be no more sheets in my
workbook. I thought of running a loop through my array with 13 woorksheets
and see if the "ActiveWorksheet" is there.

I have started to give name the arrays like:

shtArray(0) = Sheet1.Name
shtArray(1) = Sheet2.Name
:
and thought of running a Loop like:
"If ActiveSheet.Name < shtArray" Then

I has been thinking about using woorkbook_deactivate event, but can't find
out how i can get the Target range and continue with my code in a right
way.

Better ways to solve it are of course welcome, but maybe this give me a
reason to learn arrays once and for all:-)


- Regards -


You might want to consider adding a reference to Microsoft Scripting
Runtime and using something like

Sub qwerty1()
Dim x As Dictionary, i As Long
Set x = New Dictionary
For i = 1 To Worksheets.Count
x.Add Item:=Worksheets(i).Name, key:=CStr(Worksheets(i).Name)
Next
If x.Exists("Sheet3") Then
'Do whatever
Else
'Do whatever else
End If
End Sub

Alan Beban


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com