LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default How to programmatically set ControlSource?

I'm trying to set the Control Source of all form controls using a macro at
form initialization.
But my attempt below doesn't populate the ControlSource property of the form
control (textbox in this example). How can I fix this?


Sub SetControlSource()
Const RowNo As Integer = 21
Const ColNo As Integer = 46
Dim wsSheet1 As Worksheet
Dim Col As Variant

Set wsSheet1 = ThisWorkbook.Worksheets("Sheet1")

' Convert column number to text
' (e.g. ColNo = 46 refers to column AT)
Col = Left(wsSheet1.Cells(1, ColNo).Address(0, 0), _
1 - (wsSheet1.Cells(1, ColNo).Column 26))

' Set the form control's ControlSource
UserForm1.Controls("txtCol" & Col & "Row" & RowNo).ControlSource = _
"'Sheet1'!" & Col & RowNo

' Messagebox check
MsgBox "txtCol" & Col & "Row" & RowNo & " control source = " & _
"'Sheet1'!" & Col & RowNo
End Sub
 
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
controlsource cells(2,3) ? Helmut Weber[_2_] Excel Programming 2 June 10th 07 10:36 AM
ControlSource and Localization Issue?? (run-time error '380' Could not set the ControlSource property) TCook Excel Programming 1 March 4th 07 08:12 AM
.ControlSource Ctech[_128_] Excel Programming 1 March 27th 06 01:16 PM
ControlSource Greg[_20_] Excel Programming 2 April 2nd 05 04:57 AM
Controlsource David Coleman Excel Programming 5 December 28th 03 01:14 PM


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