Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Array Questions

I would like to be able to click a button and display the next element in an
array. Currently I have a loop that just cycles through the elements of the
array on a single click of the button, here is my code
Sub Array_Owners()


Dim arrOwners As Variant
Dim strCurrOwner As String
Dim intX As Integer
Dim intY As Integer
Dim intCtr As Integer
intX = 1
intY = 1



arrOwners = Sheet1.Range("S3:S12").Value




For intCtr = 1 To 10
'MsgBox "On the Clock: " & arrOwners(intY, intX)
Sheet1.Cells(1, 7) = arrOwners(intY, intX)
intY = intY + 1
Next intCtr





End Sub

thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Array Questions

DWTSG,
This was originally posted on 7/17 in response to a somewhat similar
request. It uses a Collection instead of an array. It was written to respond
to a double click on a cell but could be adapted easily to respond to a
button click. You might look up the original thread started 7/16 with
subject "Single command button to select one of several choices...".

Paste this code into a worksheet code module. It
will roll thru "Screws, Nails, Tacks" in B2 when you double-click on cell
B2. No controls required. The code contains all the necessary data. You can
specify any cell. You could put this code into a button event and change
Target to a particular cell or other object.

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B1 value among
'"Screws, Nails, Tacks" on double-click.

'Limit the effect to, oh, uh, cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instantiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Screws", "Tacks"
.Add "Nails", "Screws"
.Add "Tacks", "Nails"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub

Bob Kilmer

"DWTSG" wrote in message
...
I would like to be able to click a button and display the next element in

an
array. Currently I have a loop that just cycles through the elements of

the
array on a single click of the button, here is my code
Sub Array_Owners()


Dim arrOwners As Variant
Dim strCurrOwner As String
Dim intX As Integer
Dim intY As Integer
Dim intCtr As Integer
intX = 1
intY = 1



arrOwners = Sheet1.Range("S3:S12").Value




For intCtr = 1 To 10
'MsgBox "On the Clock: " & arrOwners(intY, intX)
Sheet1.Cells(1, 7) = arrOwners(intY, intX)
intY = intY + 1
Next intCtr





End Sub

thanks in advance.




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
Answers to questions posing more questions in a workbook sbelle1 Excel Worksheet Functions 2 August 8th 09 01:02 AM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Excel CHALLENGE...3 questions(indirect,rank,array formula)... Mlowry Excel Worksheet Functions 8 August 1st 05 07:34 AM
Array Functions - Two Questions MDW Excel Worksheet Functions 3 January 12th 05 06:54 PM


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