Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sorting Controls by Name

Like when you click the ok button on the userform?

Option Explicit
Private Sub CommandButton1_Click()
Dim myName As String
Dim ctrl As Control

Range("A1").Select
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.SpinButton Then
myName = Mid(ctrl.Name, 5) 'not like =mid() in the worksheet
ActiveCell.Value = Me.Controls("lab" & myName).Caption
ActiveCell.Offset(0, 1) = Me.Controls("txt" & myName).Text
ActiveCell.Offset(1, 0).Select
If ActiveCell.Row = 10 Then
ActiveCell.Offset(-10, 1).Select
End If
End If
Next
End Sub

I wouldn't use a variable named Name. It may be ok with VBA, but it would
confuse me.

BOBODD wrote:

I'm not sure of appropriate syntax on these forums, so I've noted comments or
what I'm trying to do in {} brackets.

How would I do this:

Private Sub FillForm()
Dim Name As String
Range("A1").Select
For Each SpinButton in UserForm
Name = Mid(Spinbutton.Name, 5, {However long Spinbutton.Name is})
ActiveCell = Label.Value {Where Label.Name = "lab" & Name}
ActiveCell.Offset(0, 1) = Textbox.Value {Where Textbox.Name = "txt"
& Name}
ActiveCell.Offset(1, 0).Select
If ActiveCell.Row = 10 Then
ActiveCell.Offset(-10, 1).Select
End If
Next
End Sub

I've been banging my head over this one for several days now. I can call
each control individually, but I have a lot of controls and I end up with a
Sub that's several pages in length.


--

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
Automatic sorting (giving max and min) based on custom sorting lis Joe Lewis[_2_] Excel Worksheet Functions 4 November 23rd 08 05:12 AM
Sorting VLookup vs Sorting SumProduct Lauren Excel Discussion (Misc queries) 1 August 21st 07 12:19 AM
Excel controls vs vba controls cmpcwil2[_6_] Excel Programming 3 April 19th 06 03:33 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM


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