userform

VBA: Detect changes in any textbox of the userform

落花浮王杯 提交于 2019-12-25 02:32:08
问题 There is a userform that has many textboxes and I need to detect changes in each. So I have write a subroutine for every textbox in the form and it turns out a large piece of code. As the code for every textbox is the same I want to optimize it. So is it possible to write just one subroutine that detect changes in any textbox of the form? 回答1: The only way do achieve that is to use a class along with WithEvents Here's a minimal example: Code for the class module named mytextbox : Private

VBA: Detect changes in any textbox of the userform

谁说胖子不能爱 提交于 2019-12-25 02:31:14
问题 There is a userform that has many textboxes and I need to detect changes in each. So I have write a subroutine for every textbox in the form and it turns out a large piece of code. As the code for every textbox is the same I want to optimize it. So is it possible to write just one subroutine that detect changes in any textbox of the form? 回答1: The only way do achieve that is to use a class along with WithEvents Here's a minimal example: Code for the class module named mytextbox : Private

Excel Macro Userform - single code handling multiple checkboxes

让人想犯罪 __ 提交于 2019-12-24 13:37:17
问题 I've got a user form that looks like the image below, with a naming convention to identify levels & positions (like the example above the pic). I have the current code below, as well - but I haven't added code for each of the "Port" checkboxes yet, and eventually I'll be inserting/removing a value specific to each checkbox into arrays based on whether they're checked/un-checked. I'd like to know about the following: Are conditions based on checking or un-checking a checkbox better chosen by

Subroutine unexpectedly ends when a Workbook is closed

故事扮演 提交于 2019-12-24 13:08:22
问题 my problem today is a part of a subroutine that inexplicably breaks its execution when a Workbook is closed. I have written the following code: Public Const Pi As Double = 3.14159265358979 Public Const Rad As Double = Pi / 180 Public CalcBook As Workbook Public FilePath As String, Files() As String Public FreqArray() As Integer Sub Main() Dim ChooseFolder As Object, FilePath As String, StrFile As String Dim i As Integer, j As Integer, k As Integer, x As Integer Dim DirNum As Integer, HNum As

Validation for Userform to check for empty controls, using loops

风流意气都作罢 提交于 2019-12-24 12:14:05
问题 After the user done entering the data. When the user click Submit button. I will check if all the textbox is not empty. The user will enter number of member, if the user enter 1 member I will check if member01 is empty, if the user enter 3 member I will check if member01, member02, member03 is empty It works for If Else but I would like to do it for loop, as it is tedious for me to do it 10 times. I don't know how do I change it from If Else to For Loop. ‘Using If Else If txtNoMember.Value =

In a VBA Userform, which event is triggered when exiting a filed

家住魔仙堡 提交于 2019-12-24 11:37:47
问题 I'm using Microsoft Office Professional Plus (64 bit) on a Windows 10 (64 bit) platform. I have a subroutine that is processed when I make a change to a Userform field called MyDate . It's called Private Sub MyDate_AfterUpdate() . It's the second field on a form. It works fine as long as the contents of the MyDate field are edited. However, if the user doesn't need to update the contents of the MyDate field because they accept the default of the field and just presses the tab key past that

Excel VBA & UserForm Login and Password VLOOKUP Table in Sheet

懵懂的女人 提交于 2019-12-24 09:41:14
问题 I've been trying to get my login userform to login when clicked based on data in a table in the workbook, but I just can't seem to get the code right. Details are: Userform username textbox = UsernameTextbox; Userform password textbox = PasswordTextbox; Userform submit button = LoginButton My workbook has a number of sheets, one of which is "Users" . In that sheet, there is a table called "Users_Table" . That table has 4 columns: ID (individual IDs for users) [Column A], Username [Column B],

Populate Combobox with Two Text Fields from an Array

五迷三道 提交于 2019-12-24 08:58:56
问题 I'm trying to get values from 2 cells in an array to populate the text field of a combobox on a userform. The values in the array look like this: A 1 B 2 C 3 B 4 I would like to make a distinction between B2 and B4 in the combobox text field. The field currently populates like B . I would like it to populate with B 2 instead. This question is partly related to this question. I tried using this that was linked from here but couldn't get the ListCount property to work. I used this to better

Select variable object with counter

混江龙づ霸主 提交于 2019-12-24 07:07:15
问题 Background: I have a collection of objects (for this example Listbox objects) in a userform using standardized names, I would like to rename them dynamically using a counter cycle. Problem: I have not figured a way if what I am asking is even possible, however, I would like to confirm it. Solution approach: Nothing so far, like I said (refer to the image above) I need a way to set the values of the objects within the for cycle, something like this: For CounterItems = 1 To 18 'Hours in

Applying vbCrLf to the content of a textbox

烈酒焚心 提交于 2019-12-24 02:45:24
问题 I've got a userform within an Excel vba project. At design-time it is empty. In the form initialize event I've got the following code: Private Sub UserForm_Initialize() txtSQL.value = _ "SELECT MyName = ""ColY"" " & vbCrLf & _ "FROM SomeTable " & vbCrLf & _ "GROUP BY Customer " & vbCrLf & _ "ORDER BY Customer DESC" End Sub I was hoping for 4 separate lines of text in the textbox but instead have the following: Am I using the wrong control? Or am I using the right control in the wrong way? 回答1