+ Reply to Thread
Results 1 to 7 of 7

VBA to lock a Form Control to a cell?

Hybrid View

  1. #1
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA to lock a Form Control to a cell?

    If you assign it to this macro, the user can move it, but as soon as they click on the combobox, it will spring back where it belongs.
    You might also want set the properties of the combobox to Move but don't resize.
    Sub stickControl()
        With ActiveSheet
            .Shapes(Application.Caller).Top = .Range("D4").Top
            .Shapes(Application.Caller).Left = .Range("D4").Left
        End With
    End Sub
    (BTW, is there any reason that the user doesn't know the most convenient location for the control? I always assume that the user knows what lay-out works better than I do.)
    Last edited by mikerickson; 01-06-2012 at 10:05 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  2. #2
    Registered User
    Join Date
    01-06-2012
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010, Excel 365
    Posts
    49

    Re: VBA to lock a Form Control to a cell?

    I attached the spreadsheet I'm working on...
    Right now I have a Button on top "Add Record" that will
    1. add a row right under Row 2
    2. insert the current date & time in B3, then copy and paste special as values in the same cell
    3. inserts a ComboBox Form Control in D3, selects the input range, linked cell (E3), drop down lines, 3-D shading and unchecks the Print object property
    4. applies the VLOOKUP function in D3 - which lists the selection from the ComboBox in the cell (if you move one of the ComboBoxes to the left or right a little, you'll see what I mean)
    5. adds another ComboBox Form Control in F3 and the VLOOKUP function for it.
    6. defaults to select cell C3 at the end
    So, since the ComboBox is created by a macro and there will be many created, I don't think the VBA below will work? But, note that I am not very familier with VBA and VBA code - I know enough to be slightly dangerous.


    And - to answer your question about why the user doesn't know the most convenient place to put the ComboBox is because the ComboBox is automatically placed where it should be by the "Add Record" macro.... The people that will be using this are not familier with using these kinds of controls - I can totally predict that someone will accidentally right click on one of them and move it... then the spreadsheet will be messed up and they won't have a clue on how to fix it.

    Also note - I would LOVE to do this in Microsoft Access... it would be SO much easier.... but none of the 5 users have Access.
    Attached Files Attached Files

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA to lock a Form Control to a cell?

    It isn't as visually appealing, but putting Data Validation on those cells is easy.
    Since the lists are on a different sheet, Named ranges ListOfDealers, ListOfStatus, etc have been added.
    (Unneeded Selecting has also been removed)
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1