Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-05-2017, 02:06 PM
Shnitzel Shnitzel is offline Adding ComboBox to be displayed from anywhere in the WORKBOOK Windows 7 32bit Adding ComboBox to be displayed from anywhere in the WORKBOOK Office 2010 32bit
Novice
Adding ComboBox to be displayed from anywhere in the WORKBOOK
 
Join Date: Jan 2017
Posts: 2
Shnitzel is on a distinguished road
Question Adding ComboBox to be displayed from anywhere in the WORKBOOK

Hello!


i'm very new to VBA for excel, and currently trying to implement a combo box in my workbook.

i have a big Worksheet which includes many worksheets, one of them has a list of guides' names, which i selected there ("A2:A80") and named it "Guides_names".
i also added a vba macro (in module) which can and is activated from anywhere in the workbook, to display the list:

Code:
   With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Guides_names"
    .IgnoreBlank = True
    .InCellDropdown = False
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
  End With
and it works well: it implements the list in any cell i choose and opens it, and the selection is then displayed in the cell.
But: 1. Font of the names in the lise are very small; 2. There is no auto-refill.

So i decided to use it and hide the validation list, and to add Combo box.
I found lots of examples and did manage to add a nice combo box
into one of the sheets and it perfectly opens while double-clicking any cell i click inside the sheet but when i implement similar code in a module:
i can't automatically open the list (the problem is with the Me.TempCombo.DropDown: it doesn't know the ME), and after selecting a value from the list the combo box keep being displayed, and when i try to activate it from another sheet it won't work at all...
My main question is if there is any way to implement a combo box that can be activated from any cell in the workbook,
and how can combobox_lostFocus and other sheets function can be implemented outside, in the workbook.
here is my current code... basiclly based on Debra Dalgleish code.
Thank you for any help or suggestion!

Code:
 
Sub Select_Guide()

Dim str As String
Dim cboTemp As OLEObject
Dim rngSelectedRange As Range
Dim ws As Worksheet
Set ws = ActiveSheet

' Here i use the original code:
 With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Guides_Names"
    .IgnoreBlank = True
    .InCellDropdown = False
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
 End With

  Set rngSelectedRange = Range(ActiveCell, ActiveCell.Offset(numRows, numCols))

  Set cboTemp = Worksheets("dbdb").OLEObjects("TempCombo")

  On Error Resume Next
  With cboTemp
  'clear and hide the combo box
    .ListFillRange = "Guides_Names"
    .LinkedCell = ""
    .Visible = False
  End With
  On Error GoTo errHandler

  If rngSelectedRange.Validation.Type = 3 Then
    'if the cell contains a data validation list
     Application.EnableEvents = False
    'get the data validation formula
    str = rngSelectedRange.Validation.Formula1
    str = Right(str, Len(str) - 1)

    With cboTemp
      'show the combobox with the list
      .Visible = True
      .Left = rngSelectedRange.Left
      .Top = rngSelectedRange.Top
      .Width = rngSelectedRange.Width + 5
      .Height = rngSelectedRange.Height + 5
      .ListFillRange = str
      .LinkedCell = rngSelectedRange.Address
    End With
    cboTemp.Activate

    'open the drop down list automatically
    ' Me.TempCombo.DropDown - worked only when called by double_click function
    TempCombo.DropDown  ' This doesn't really opens the combo box,  also cboTemp.DropDown doesn't
  End If

  errHandler:
    Application.EnableEvents = True
    Exit Sub
End Sub
Reply With Quote
 

Tags
macro problem, vba excel



Similar Threads
Thread Thread Starter Forum Replies Last Post
data entered in one workbook should be updated in other relevant workbook based on the date vedha Excel 0 04-24-2015 08:45 PM
How to add attached excel workbook with hyperlink in the same workbook lynchbro Excel Programming 0 02-24-2015 01:29 PM
Adding ComboBox to be displayed from anywhere in the WORKBOOK Adding a long list of values to a combobox in Word 2003? ll4u76 Word VBA 1 04-13-2012 03:37 AM
Range(Cell1,Cell2) Error on another workbook controlling some other workbook? tinfanide Excel Programming 1 02-09-2012 04:08 PM
Adding ComboBox to be displayed from anywhere in the WORKBOOK macro to transfer data from one workbook to another workbook virsojour Excel Programming 5 02-01-2011 08:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft