I have two radio buttons. Let's call them Button_1 and Button_2. They both have code behind the click event.
One of the lines in the Button_1 code makes the value of Button_2 false. If Button_2's value at the time is true, the Button_2 click event fires off and runs through it's code.
How do I disable Button_2's click event in this scenario so the value changes, but the code in it's click event won't run?
I tried application.enableevents = false, but that didn't do it.
I am creating a form that performs several different functions. I would like to force a sequence of these functions by enabling/disabling the controls based on a variable.
For example, a form as two buttons Button1 and Button2. By default, Button1 is ENABLED and Button2 is DISABLED. When Button1 is clicked, a macro is run, where an Enable_Button2variable is initialized to FALSE. The last line of the macro sets the Enable_Button2 variable to TRUE. Then, because Enable_Button2 is now TRUE, Button2 then becomes ENABLED.
I am trying to apply this strategy to a ComboBox, ListBox and CommandButtons. I'm not sure what event to trigger on to poll the Enable_Button2 to enable/disable the control.
I'm currently building an Excel database. This database has a few comboboxes and checkboxes that are tied to each other. If I select the combobox option of "Years", the "Quarters" combobox must be greyed out. In addition depending on which option is chosen, the relevant check boxes must be enabeled or disabled. I've written some code which runs fine, until I try and activate another macro button or if I add and rename a sheet(which is not linked to anything). What should I do? Here is a sample of my code. I have a feeling it's really obviouse but I cant see it..
way to allow a user to add a control to a userform without going into the VBE. Here is the situation, I am developing a userform to calculate a projected budget. I want the user to be able to select the number of controls to add, and click a command button to add them. Based on other selections that the user makes, different controls would automatically be added. Is this possible? As a follow up, will I be able to atttach code to these new controls?
I'm making a form in excel to retrieve a number of welds. This number needs to be passed on to the next form to dynamically create an identical number of input fields (a set of text boxes and labels essentially). Any ideas on how I might do this? Is it even possible? I would like to avoid having 100 (my assumed maximum, it could get changed) sets of input fields and hiding the unused ones,
I'm trying to programatically remove select controls from a worksheet (I want to keep combobox and buttons, but remove all else). I execute the following code, but keep getting a run time error "The index into the specified collection is out of bounds" about half way through the deletes.
Dim i As Integer Dim counter As Integer i = ActiveSheet.Shapes.Count For counter = 1 To i If ActiveSheet.Shapes(counter). Name = "ComboBox1" Then Goto SkipDelete If ActiveSheet.Shapes(counter).Name = "CommandButton1" Then Goto SkipDelete If ActiveSheet.Shapes(counter).Name = "CommandButton2" Then Goto SkipDelete If ActiveSheet.Shapes(counter).Name = "CommandButton3" Then Goto SkipDelete ActiveSheet.Shapes(counter).Delete SkipDelete: Next counter
Im using the following code on a userform to link the spinner and a textbox:
Private Sub Marketing_spn1_Change() 'ensures the text box changes when spinner is changed Marketing_txt1.Text = Marketing_spn1.Value End Sub
Private Sub Marketing_txt1_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' ensure value typed in is valid newvalue = Round(Val(Marketing_txt1.Text), 0) If newvalue < Marketing_spn1.Min Then newvalue = Marketing_spn1.Min If newvalue > Marketing_spn1.Max Then newvalue = Marketing_spn1.Max ' set the spinner value to keep in step with new value Marketing_spn1.Value = newvalue ' set the textbox to the appropriate value Marketing_txt1.Value = newvalue End Sub
I have many spinners and textboxes with the same name (marketing_txt2, marketing_spn3 etc) on both this userform and on other userforms I shall be doing. Is there any way of just writing this code once, rather than copying and pasting it for each spinner/textbox?
This code create a userform on the workbook opening .I'm having problems with
1. Closeing the Visual basic window after this procedure runs 2. Being able to use the create userformstext box value in other procedures 3. how to delete the userform on close
Sub AddUserFormInputRequest() Dim objVBProj As VBProject Dim objVBComp As VBComponent Dim objVBFrm As UserForm Dim objChkBox As Object Dim x As Integer Dim strCode As String Dim firstLine As Long, SecondLine As Long Set objVBProj = Application.VBE.ActiveVBProject Set objVBComp = objVBProj.VBComponents.Add(vbext_ct_MSForm) With objVBComp . Name = "InputRequest" . Properties("Width") = 200 .Properties("Height") = 100......................
I would like to have 4 calendar controls in a worksheet, but even with only two controls I am receiving a Compile Error - Ambiguous name detected: Worksheet_BeforeDoubleClick
I am trying to dynamically add controls to my user form based on some values in my cell. I am successfully able to create a text box dynamically but my label is not getting displayed. here is my code
Private Sub UserForm_Activate()
On Error Resume Next If (ThisWorkbook. Sheets("Sheet2").Cells(1, 8) <> "FALSE") Then Dim ctl As Control Dim ctl1 As Control
Set ctl1 = Me.Controls.Add("Forms.Label.1", ctl1, True) With ctl1
I have a code that adds a couple of ComboBoxes to a UserForm (the number of ComboBoxes is variable). Now that I want to control a certain ComboBox based on the selected value of another ComboBox (change or click event), how do I do that via VBA code?
I have these codes in place in my excel file, there is nothing wrong with them at all. Here is the the problem : My superior runs the macros in place in the file almost daily, and when he is done he then closes it and all is well. The macros does things to other files so they are changed in a way that the supervisors like them. I avoided putting macros in these individual files, because of the attempt to make it as simplistic as possible without them being able to affect overall file. The problem happens when he (my superior) accidently makes a change in the primary sheet in the workbook with all the macros, it affects alot of my formulas and macros that are already in place. Within this workbook, it keeps a log of things from the other files results, so I have to have a record of it in the workbook, hence having a save event in place.
The Question: Is it possible to create a macro button, that will allow him to disable the codes below, so that he can close it and open again, so that it doesn't show any of the errors that happens by accident and try to close it again so there is no errors? Basically, I am asking what is the code for this, and where would I place it in.
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim mylogoff Set mylogoff = Sheet1. Range("A65536").End(xlUp).Offset(0, 1) mylogoff.FormulaR1C1 = "=NOW()" mylogoff.Copy mylogoff.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = Fals mylogoff.Offset(0, 1).FormulaR1C1 = "=RC[-1]-RC[-2]" Application.DisplayAlerts = False Sheets("Start Here").Select ThisWorkbook.Save ThisWorkbook.Close End Sub......................
Private Sub Workbook_Activate() Application.CutCopyMode = False Application.OnKey "^c", "" Application.CellDragAndDrop = False End Sub Private Sub Workbook_Deactivate()
[Code] .......
OR This one:
Option Explicit Private Sub Workbook_Activate() With Application .CutCopyMode = False .CellDragAndDrop = False
[Code] ........
I noltice that one uses "Option Explicit" and one doesn't, one seems to be longer than the other, but when I tested both, they both seem to do the same thing. I did notice that neither one of them prevents a "paste" into the worksheet when something is copied from an outside source, but that is not a concern right now!!!
I created a form using multiple text boxes and combo-boxes using Excel VBA controls but do not know how to enable the ability to tab between those boxes. "Auto Tab" doesn't seem to do it.
I have added subtotals to a worksheet, as I have many times before, but this time I don't see any controls off to the left. I am at a loss as to why this might be happening or how to get them to display. Have I toggled something off or on that might be causing this?
My excel macro's run fine under Windows 2000 Pro, and Office 2000. The company got a new computer with Windows XP. I now have macros that run OK however I keep getting a pop up message stating. Warning..An active X component is being loaded. I must press OK and the program will run fine. How can I get rid of the Pop up active X message.
way of setting the values of textbox controls, the way im using below is very repetitive and has to be run through every time a combobox1 is changed. Im also going to have to add a lot more case scenarios in the short future.
Private Function setform() Dim Xeng As Boolean
For Each ctl In Me.Controls If TypeOf ctl Is MSForms.TextBox Then ctl.Enabled = True ctl.Locked = False ctl.Value = "" End If Next
I have a ListBox in my worksheet "A", and I'm tryin to acces to it... I want to use that ListBox like a log to print the error i have found while running my code. The name of that ListBox is "IncongruenciesListBox".
now if that ListBox was in a userform, i can access to it easily, but if it is in the worksheet how can i change (add more rows) to it?
I tried:
Dim WS As WorkSheet Set WS = ThisWorkBook.WorkSheets("A") If added = False Then WS.IncongruenciesListBox.AddItem ("error")
And there is a message saying it cant find "IncongruenciesListBox".
I have a userform that has nested multipages (5 in the outer page, 4 in the inner page).
On each of these multipages, I want to have the same controls (sliders) laid out in the same order - but with unique names, named after their tab location, for each control so I can use their value property later in the code.
I've designed the layout and named all the controls on my first sheet (e.g. Slider1Outer1Inner1). I now need a way of automating the replication of these across the other 19 sheets (including the nested inner multipage!); so that equivalent slider for example would be called Slider1Outer1Inner2, Slider1Outer1Inner3 etc.
I'm not sure about coding VBA to act on items within VBA...
VB: " For each multipage in outer For Each multipage In inner For Each Object In current multipage Copy inner.object -> Next multipage Inner.object.name = CurrentOuter & CurrentInner & CurrentSlider "
I have a spreadsheet with numerous check boxes. Everything looks great when I do a "print preview", but after I close the preview and return to the spreadsheet, a bunch of the check boxes have moved! Have I got a property improperly set, or is it something more sinister? I've looked all over, and can't find an explanation of what the various property settings mean...
What's the best way to hide controls on a userform? I have a userfrom with 2 datepicker one for start date and one for end date. I want them hidden until I use checkbox and check it to appear. I am using this code but nothing is work.