PC Review


Reply
Thread Tools Rate Thread

How to Creating Array

 
 
K
Guest
Posts: n/a
 
      16th Dec 2009
Hi all, I got macro (see below)

Private Function LabelNormal()
On Error Resume Next
Dim ctl As Control


For Each ctl In Me.Controls
If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
"Label9" Then
With ctl
.SpecialEffect = 1 'Raised
.BackColor = 8421504 'Grey
.ForeColor = 16777215 'White
.FontWeight = 400 'Normal
End With
End If
Next

End Function


the above macro fine but I want to change the line where it say
If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
"Label9" Then

to
If TypeOf ctl Is Label And ctl.Name <> Array("Label10" , "Label9")
Then

I tried it but its not working. Basically I want macro to go through
all the names I put in Array and change only those controls which
names are not array. Please can any friend can help as I always had
problem creating array in macros
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      16th Dec 2009
Try

If TypeOf ctl Is Label And IsError(Application.Match(ctl.Name,
Array("Label10","Label9"),0) Then



---
HTH

Bob Phillips


"K" <(E-Mail Removed)> wrote in message
news:b8d953e5-2c4a-405d-afe0-(E-Mail Removed)...
> Hi all, I got macro (see below)
>
> Private Function LabelNormal()
> On Error Resume Next
> Dim ctl As Control
>
>
> For Each ctl In Me.Controls
> If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
> "Label9" Then
> With ctl
> .SpecialEffect = 1 'Raised
> .BackColor = 8421504 'Grey
> .ForeColor = 16777215 'White
> .FontWeight = 400 'Normal
> End With
> End If
> Next
>
> End Function
>
>
> the above macro fine but I want to change the line where it say
> If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
> "Label9" Then
>
> to
> If TypeOf ctl Is Label And ctl.Name <> Array("Label10" , "Label9")
> Then
>
> I tried it but its not working. Basically I want macro to go through
> all the names I put in Array and change only those controls which
> names are not array. Please can any friend can help as I always had
> problem creating array in macros



 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      16th Dec 2009
This should help you. You have to setup an array and loop thru the values of
the array to do what you are wanting to do. By the way, I'm not sure why you
have On Error Resume Next, but I would recommend you not put that in your
code, because it can cause unwanted results if an error is thrown of which
you are not expecting.

I hope this helps! If so, let me know. Click "YES" below.

Option Explicit

Private Function LabelNormal()

Dim ctl As Control
Dim myArray As Variant
Dim i As Long

myArray = Array("Label9", "Label10")

For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
For i = LBound(myArray) To UBound(myArray)
If ctl.Name <> myArray(i) Then
With ctl
.SpecialEffect = 1 'Raised
.BackColor = 8421504 'Grey
.ForeColor = 16777215 'White
.FontWeight = 400 'Normal
End With
End If
Next i
End If
Next ctl

End Function

--
Cheers,
Ryan


"K" wrote:

> Hi all, I got macro (see below)
>
> Private Function LabelNormal()
> On Error Resume Next
> Dim ctl As Control
>
>
> For Each ctl In Me.Controls
> If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
> "Label9" Then
> With ctl
> .SpecialEffect = 1 'Raised
> .BackColor = 8421504 'Grey
> .ForeColor = 16777215 'White
> .FontWeight = 400 'Normal
> End With
> End If
> Next
>
> End Function
>
>
> the above macro fine but I want to change the line where it say
> If TypeOf ctl Is Label And ctl.Name <> "Label10" And ctl.Name <>
> "Label9" Then
>
> to
> If TypeOf ctl Is Label And ctl.Name <> Array("Label10" , "Label9")
> Then
>
> I tried it but its not working. Basically I want macro to go through
> all the names I put in Array and change only those controls which
> names are not array. Please can any friend can help as I always had
> problem creating array in macros
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an ARRAY UDF kittronald Microsoft Excel Programming 0 7th Aug 2011 06:02 PM
Help creating an array kidkosmo Microsoft Access 6 2nd Mar 2009 03:35 PM
creating an array Richard Microsoft Excel Programming 4 15th Mar 2007 01:06 PM
Creating an array Eric Microsoft Excel Programming 1 12th Jan 2004 08:25 PM
Creating an Array from a multidimensional array @ nospam.com Microsoft C# .NET 1 20th Aug 2003 12:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:51 AM.