Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    Amsterdam
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Controlsource property syntax (Excel 97 on NT)

    Hello

    I'd really like to bind the controls on a form I've created to cells on a worksheet. So far I've found that I can do this:

    controlname.ControlSource = '"sheetname!A5"

    This is a start. but I would really like to be able to refer to the cell using notation like
    sheets("sheetname").cells(5,1)

    This doesn't seem to be possible and the web seems very short of examples using this property. Does anyone have any ideas as to how I can go about this, short of converting my column numbers into letters and using "sheetname!A5"?

    Thanks in advance

    Mark

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Controlsource property syntax (Excel 97 on NT)

    If you append .Address to you current method it should work, e.g.<pre> Sheets("sheetname").cells(5,1).Address</pre>


    Andrew C

  3. #3
    New Lounger
    Join Date
    Nov 2001
    Location
    Amsterdam
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Controlsource property syntax (Excel 97 on NT)

    Thanks very much Andrew, that works well. Just one quirk, no matter what I specify in the worksheet portion, the cell reference comes from the active worksheet! I can get round it easily enough but what strange behaviour.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Controlsource property syntax (Excel 97 on NT)

    Hi,
    I suspect that the Address property only actually returns the local address (i.e. just A5 or whatever), so you would need to use something like:
    <pre> With sheets("sheetname")
    controlname.ControlSource = "'" & .Name & "'!" & .Cells(5, 1).Address
    End with
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •