I have a combo box drop down with search suggestions, made from code here:
http://trumpexcel.com/2013/10/excel-drop-down-list-with-search-suggestions/
It works very well, but when I'm on another sheet and pressing "Enter", the search field randomly pops up in the sheet
It's not even the full box, just the blue field
Any insights on disabling it? The only success I've had is turning calculation to manual, but the workbook needs automatic calculation
Thanks!
I ran into a similar issue with my own VBA version of a smart search bar. How I fixed it was by doing the following:
Private Sub ComboBox1_Change()
If ComboBox1.Value = "" Then Exit Sub '<------ Problem solved.
ComboBox1.ListFillRange = "DropDownList"
Me.ComboBox1.DropDown
End Sub
OR
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim SheetWithComboBox As Worksheet: Set SheetWithComboBox = ThisWorkbook.Sheets(1)
If ThisWorkbook.ActiveSheet.Name <> SheetWithComboBox.Name Then
ComboBox1.Visible = False
Else: ComboBox1.Visible = True
End If
End Sub
#Tyeler
Thanks for your help, your thinking helped me think of a way
Private Sub ComboBox1_change()
Dim sht1 As Worksheet
Set sht1 = Worksheets("xxx")
If ThisWorkbook.ActiveSheet.Name = sht1.Name Then
ComboBox1.ListFillRange = "DropDownList"
Me.ComboBox1.DropDown
Call macro1
Else: Exit Sub
End If
End Sub
I found a solution that, at least for me, works for all sheets.
Private Sub Combobox_Get_Focus()
ComboBox1.ListFillRange = "DropDownList"
Me.ComboBox1.DropDown
End Sub
Related
I have a button in the "code module" which runs a request. Next to the Button is a label included which shows a check mark a soon as the button has finished running.
The button code is in the code modul. The codes for the label with the check mark is inlcuded in the workbook and sheet modul.
Now, the issue is when I push the button it runs perfectly fine and does what it supposed to but the label with the check mark does not get activated. The reason might be because I have not included/referenced the workbook/sheet modul in my code modul. Hope for a bit help.
Code in workbook Module:
Option Explicit
Private Sub Workbook_Open()
Call Tabelle1.prcResetLabels
End Sub
Code in Sheet Module:
Option Explicit
Private Sub Schaltfläche2_Klicken()
Call prcSetLabel(probjLabel:=Label1)
End Sub
Private Sub prcSetLabel(ByRef probjLabel As MSForms.Label)
With probjLabel
.Caption = "P"
End With
End Sub
Friend Sub prcResetLabels()
Dim objOLEObject As OLEObject
For Each objOLEObject In OLEObjects
With objOLEObject
If .progID = "Forms.Label.1" Then _
.Object.Caption = vbNullString
End With
Next
End Sub
Code in Codemodul:
Public Sub Schaltfläche2_Klicken()
With Sheets("Table1")
.Range("A1").End(xlUp).Offset(1, 0).Value = Environ("USERNAME")
End With
End Sub
The answer ist simple this:
Sub Schaltfläche2_Klicken()
Call prcResetLabels
With Sheets("Table1")
.Range("A1").End(xlUp).Offset(1, 0).Value = Environ("USERNAME")
End With
Call prcSetLabel(probjLabel:=Table1.Label1)
End Sub
Private Sub prcSetLabel(ByVal probjLabel As Object)
With probjLabel
.Object.Caption = "P"
End With
End Sub
Public Sub prcResetLabels()
Dim objOLEObject As OLEObject
For Each objOLEObject In Table1.OLEObjects
With objOLEObject
If .progID = "Forms.Label.1" Then _
.Object.Caption = vbNullString
End With
Next
End Sub
I'm trying to make a macro that clicks all the buttons in any document by getting all the buttons names and evaluating a call to these functions.
Code:
Private Sub CommandButton1_Click()
MsgBox "b"
End Sub
Private Sub CommandButton2_Click()
MsgBox "a"
End Sub
Sub test_macro()
For Each S In Worksheets(1).OLEObjects
Evaluate ("Call " + S.Name + "_Click")
Next
End Sub
What can be the problem here? and is there maybe another way to do it?
See if this works.
For Each OLEObject In Worksheets(1).OLEObjects
If TypeName(OLEObject.Object) = "CommandButton" Then OLEObject.Object = True
Next
Here are some additional documentations on OLEObject.
I need this code to work for all sheets:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.ScreenUpdating = True
End Sub
Right now I've been adding it to every sheet one by one, but how do I just add it to the workbook so every sheet has it?
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.ScreenUpdating = True
End Sub
This worked for me. What I had to do was change my object to include the workbook itself. I clicked on the dropdown to see my available options which is where I found the one I needed.
Bad: Worksheet_SelectionChange
Good: Workbook_SheetSelectionChange
I've created a menu to navigate through sheets. But when I use one of the buttons to go to another sheet and type something in this another sheet the things that I type appear in the first one. Although when I use the tabs to jump to one sheet to another it works fine. Seems to be that the macro is considering a relative reference instead a absolute one.
Here's what my macro does (or at least should):
Private Sub cadastrar_clientes_Click()
Application.ScreenUpdating = False
Menu.Hide
Sheets("Clientes").Select
Range("A1048576").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Select
End Sub
Notes:
I've tried to use ".activate" instead of ".select".
I've tried to use only "Sheets("Clientes").Select", even so the bug occurs.
To execute "Excel /unregserver" on the Windows CMD solved my problem once, but I couldn't do this again. It doesn't seems to work anymore.
I did a menu like this one once, but I didn't had these problems.
When the workbook opens the following code is executed:
Private Sub Workbook_Open()
Application.DisplayFullScreen = True
Application.DisplayFormulaBar = False
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayWorkbookTabs = False
End Sub
That's it. I hope that somebody could help me.
Replace all code on VBA module Menu with this (tested in the file you provided)
Option Explicit
Private Sub fechar_menu_Click()
Menu.Hide
End Sub
Private Sub novo_pedido_Click()
goToTab ActiveWorkbook.Worksheets("Novo pedido"), "B5"
End Sub
Private Sub ver_pedidos_Click()
goToTab ActiveWorkbook.Worksheets("Consultar pedido"), "F1"
End Sub
Private Sub cadastrar_clientes_Click()
goToTab ActiveWorkbook.Worksheets("Clientes")
End Sub
Private Sub cadastrar_produtos_Click()
goToTab ActiveWorkbook.Worksheets("Produtos")
End Sub
Private Sub cadastrar_transportadoras_Click()
goToTab ActiveWorkbook.Worksheets("Transportadoras")
End Sub
Private Sub painel_financeiro_Click()
goToTab ActiveWorkbook.Worksheets("Painel Financeiro"), "B3"
End Sub
Private Sub goToTab(ByRef ws As Worksheet, Optional cel As String = vbNullString)
Menu.Hide
Application.ScreenUpdating = False
With ws
.Activate
If Len(cel) = 0 Then
.Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).Select
Else
.Range(cel).Select
End If
End With
Application.ScreenUpdating = True
End Sub
Well, I guess I know a lot more about the problem now. I've tested the workbook over various computers and came to the conclusion that the problem is within the Office 2013. I haven't seem this issue when running the 2007 or 2010 version. So far I haven't come to a solution. I would like to thanks Paul Bika for helping.
What I am trying to accomplish is fairly simple. When a user selects a sheet, I would like a message box to appear. Meaning: I'm currently viewing Sheet1, I click on the Sheet2 tab and a message pops up before I can do anything. I can't seem to find the event that fires when moving to a different sheet.
Events I've tried: Workbook_SheetActivate and Worksheet_Activate
Private Sub Workbook_SheetActivate(ByVal sh As Object)
MsgBox ("Example Message")
End Sub
Or
Private Sub Worksheet_Activate()
MsgBox ("Example Message")
End Sub
I've done some googling and most things are about when cell values change or the cell selection changes.
This should work:
Private Sub Worksheet_Activate()
MsgBox "you never visit...you never call....you never write"
End Sub
However:
code must be in the worksheet code area
macros must be enabled
events must be enabled
You could use the following in the "ThisWorkbook" module to fire a message whenever you change sheets within the workbook.
Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox Sh.Name & " activated!"
End Sub
This will solve the problem without having to add Private Sub Worksheet_Activate() to every worksheet's code module.
Here is a link to all the worksheet events available in Excel:
http://dmcritchie.mvps.org/excel/event.htm
Private Sub Worksheet_Activate()
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) -- (additional examples)
Cancel = True 'turn off Edit mode when using “Edit directly in a cell”
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True 'turn off Edit mode when using “Edit directly in a cell”
Private Sub Worksheet_Calculate()
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False 'should be part of Change macro
Application.EnableEvents = True 'should be part of Change macro
Private Sub Worksheet_Deactivate()
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Doesn't Worksheet_Activate work for you?
You need to have the event in the worksheet that is being activated - that is, if you put it is sheet 2, it will fire only when that sheet is opened.
This worked in sheet 2 of my workbook.
Sub worksheet_activate()
MsgBox "activated!"
End Sub