+ Reply to Thread
Results 1 to 3 of 3

Using VBA to set the LinkedCell of an ActiveX Combo Box

  1. #1
    Registered User
    Join Date
    02-25-2022
    Location
    United States
    MS-Off Ver
    365
    Posts
    3

    Question Using VBA to set the LinkedCell of an ActiveX Combo Box

    Hi all! I'm having some issues with a Combo Box that I cannot for the life of me figure out. I am trying to have a single Combo Box that jumps around to whichever cell the user selects in a specific column on a spreadsheet and to then dynamically change the LinkedCell of the Combo Box to the selected cell. I've gotten everything working except for the LinkedCell part - here's the code I'm currently running with:

    PHP Code: 
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        
    Dim WB_Timesheet As Workbook
        Dim WS_Timesheet 
    As Worksheet
        Dim NumberOfCellsSelected 
    As Integer
        Dim CB 
    As Shape
     
        Set WB_Timesheet 
    Application.ActiveWorkbook
        Set WS_Timesheet 
    WB_Timesheet.Sheets("Timesheet")
        
    Set CB WS_Timesheet.Shapes("ComboBox_ClientMatter")
        
    NumberOfCellsSelected Target.Cells.Count
        
        
    If NumberOfCellsSelected 1 Then
            CB
    .Visible False
        
    ElseIf Selection.Count 1 Then
            
    If Not Intersect(TargetRange("C6:C10000")) Is Nothing Then
                Dim Position_Left 
    As String
                Dim Position_Top 
    As String
                Dim CB_Height 
    As String
                Dim CB_Width 
    As String

                Position_Left 
    ActiveCell.Left
                Position_Top 
    ActiveCell.Top
                CB_Width 
    ActiveCell.Width 15
                CB_Height 
    ActiveCell.Height 2
                            
                With CB
                    
    .Visible True
                    
    .Left Position_Left
                    
    .Top Position_Top
                    
    .Width CB_Width
                    
    .Height CB_Height
                    
    .ControlFormat.LinkedCell ActiveCell.Address
                End With
            
    Else
                
    CB.Visible False
            End 
    If
        
    End If
    End Sub 
    The code keeps bugging out on the line of ".ControlFormat.LinkedCell = ActiveCell.Address". I've tried what feels like a million different formulations of this (including not using the ".ControlFormat" portion, messing around with the stuff after the "=", etc.), but I keep getting the same run-time error '438'. If anyone could help me figure out what I'm doing wrong I would be extremely grateful.

    Also, as an aside, if anyone knows how I can use VBA to (i) put the cursor into the Combo Box and (ii) make it to where, upon initially selecting/targeting the Combo Box, it selects all of the text therein (i.e., something akin to pressing "Ctrl+a"), I would also very much appreciate that as well. (This would just be an added bonus and I'm mainly just looking to figure out how to alter the linked cell.)

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Using VBA to set the LinkedCell of an ActiveX Combo Box

    If it's an activex combo box then

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    02-25-2022
    Location
    United States
    MS-Off Ver
    365
    Posts
    3

    Re: Using VBA to set the LinkedCell of an ActiveX Combo Box

    Quote Originally Posted by Andy Pope View Post
    If it's an activex combo box then

    Please Login or Register  to view this content.
    That did the trick! Thank you so much!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Combo-box (activex) copy paste value into combo-box
    By exceliousss in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2018, 08:23 AM
  2. ActiveX Spin Button LinkedCell Question
    By speed007 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-21-2014, 08:08 PM
  3. Replies: 8
    Last Post: 12-26-2013, 02:23 PM
  4. ActiveX combo-box value depends on other combo-box value
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 09-27-2013, 05:24 PM
  5. Excel 2007 ActiveX Combobox - LinkedCell automatically change w/ copy/paste
    By jdgonzal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2013, 05:46 PM
  6. Code to change LinkedCell of ActiveX ComboBox
    By ozhunter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-08-2011, 07:10 AM
  7. Combo box and Linkedcell does not work in Excel 2003
    By Tvnguye in forum Excel General
    Replies: 7
    Last Post: 12-30-2005, 02:45 PM

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