I have an Excel user form with two text boxes. When I try to enter a value in one of them, Excel freezes and stops working. But the strange thing is that this works on other computers in the office which are exactly the same.
It is a really simple user form with two text boxes, set to change, and one button.
I'm not sure if it's because of Excel, maybe something in Windows.
I have Excel 2016 and Windows 10 on my computer.
Has anyone had this problem?
Private Sub applyCommandButton_Click()
Range("A3").Value = TextBox1.Value & " " & TextBox2.Value
End Sub
Private Sub TextBox1_Change()
Range("A1").Value = TextBox1.Value
End Sub
Private Sub TextBox2_Change()
Range("A2").Value = TextBox2.Value
End Sub
Related
I want to use VBA code to pull up my form. Right now the code is causing a runtime error on Sub UserForm_Initilize(). I don't know a lot about VBA. I know I might need to do something like column.selectAll but I am not sure assume I am trying to select the first 4 columns for my form. Thanks
Sub UserForm_Initialize()
Me.TextBox1.Value = Sheet1.Range("H" & Rows.Count).End(xlUp).Value
End Sub
Sub Rectangle1_Click()
UserForm1.Show
End Sub
Entering data via a userform. After a few entries I can no longer see the active cell and I can't scroll the sheet while the userform is active. I would like to have the sheet auto-scroll to keep the active cell/row visible while I enter data on the userform.
I've tried adding some code I found online but they've all failed to get the result I'm looking for.
Private Sub Label1_Click()
End Sub
Private Sub Label2_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_AfterUpdate()
Dim emptyRow As Long
If TextBox1.Value <> "" And TextBox2.Value <> "" Then
With ThisWorkbook.Sheets("RO-BOX DETAILS")
emptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(emptyRow, 1).Value = TextBox1.Value
.Cells(emptyRow, 2).Value = TextBox2.Value
TextBox1.Value = ""
TextBox2.Value = ""
TextBox1.SetFocus
End With
End If
End Sub
Private Sub UserForm_Click()
End Sub
I'm not experienced with VBA. I honestly thought there would be a simple code snippet I could add in, but so far, no joy.
I scan into textbox 1 and it moves the focus to textbox 2
I scan into textbox 2 and it adds the data to the next empty row - no
clicking 'OK' required.
The focus returns to textbox 1.
Repeat
Now I just want it to keep the next empty row visible so I can see the entries go in on the fly. Basically to ensure they scanned correctly. Right now, I have to close the userform every so often and scroll down and look manually. PITA. :)
It won't quite achieve the autoscrolling you requested, but you could try calling the userform with it's ShowModal property set to "modeless". That would at least allow the user to manually scroll the sheet.
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/showmodal-property
...there's no example to follow on that page, but it would go something like...
sub CallNormsUserForm()
NormsUserForm.show vbModeless
end sub
I am trying to figure out how to display newly entered text from one userform text box to another userform text box in a new line below. Pretty much I want it to a multiline input. Here is the code I am using so far:
Private Sub CommandButton1_Click()
UserForm1.TextBox1.Value = TextBox1.Value & vbNewLine
End Sub
Try this
Private Sub CommandButton1_Click()
UserForm1.TextBox1.Value = UserForm1.TextBox1.Value & vbNewLine & UserForm2.TextBox1.Value
End Sub
The VBA code below is meant to allow only certain users to tick & un-tick a checkbox. However, the problem is that if I check the box and then close the spreadsheet, when I re-open the excel file the 'tick' is no longer there. It's like the code does not save the 'tick' action. Basically, if I check the box I want that to stay like that, even after closing the spreadsheet. In the VBA code below i added ThisWorkbook.Save in order to save the "Tick" action but it simply saves the spreadsheet instead of saving the "Tick" in the check box. Could you please advise what's wrong in my code? I've asked this question before but unfortunately nobody seemed to be able to find a solution. thanks so much
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
If (UCase(Environ("username")) = "TESTNAME") Then
'Do nothing
Else
'Uncheck because user not matching
CheckBox1.Value = False
MsgBox ("You are not authorized to tick this box.")
End If
End If
ThisWorkbook.Save
End Sub
on my sheet1 I have a commandButton (bShow) and in the code behind:
Private Sub bShow_Click()
UserForm1.Show
End Sub
then I have a UserForm named UserForm1 with a checkbox (named checkBox1) and a button named saveButton, and with a code behind:
Private Sub saveButton_Click()
Sheets(1).Cells(1, 1).Value = UserForm1.CheckBox1.Value
End Sub
with this setup in cell("A1") appears TRUE or FALSE depending on the checkbox state
i hope it helps
EDIT1:
by opening the Form reading the value from the sheet:
Private Sub UserForm_Activate()
UserForm1.CheckBox1.Value = Sheets(1).Cells(1, 1).Value
End Sub
EDIT2:
be aware of error handling (eg.: what if cell value is neither TRUE nor FALSE) But that I leave to you
In my Userform I have a textbox "ADD_Inc_DATE_TXT" which the user manually enters the date of the incident.
I have another textbox "TxT_SWIRL_DueDate" which should display the result of the adding of 28 days to the date entered in the "ADD_Inc_DATE_TXT" textbox or even just add 1 month to the date of the incident.
I have tried this in a module named "Mod_SWIRL_Due_Date":
Sub SWIRL_ExpiryDate()
TxT_SWIRL_DueDate = CDate(ADD_Inc_DATE_TXT)
ADD_Inc_DATE_TXT = DateAdd("m", 1, ADD_Inc_DATE_TXT)
End Sub
But this doesn't seem to do anything at all.
I would like the "TxT_SWIRL_DueDate" to display the expiry date when the "ADD_INC_Time_TXT" textbox is selected.
And in anticipation of the User amending the Incident Date, I'd like it to update the TxT_SWIRL_DueDate with the amended date.
Further Information:
I have included below all the code I have relating to dates. I have 4 Date Pickers/Popup Calendars ... and none of the dates come up in the dd/mm/yyyy format. (having some problem with putting the code in the 'code sample' )
Private Sub Calendar1_Click()
ADD_Inc_DATE_TXT.value = CalendarForm.GetDate
If IsDate(ADD_Inc_DATE_TXT.Text) Then
Me.LBL_Inc_Day_Type.Caption = Format(ADD_Inc_DATE_TXT.Text, "ddd")
End If
If IsDate(ADD_Inc_DATE_TXT.Text) Then
Me.ADD_Inc_DATE_TXT.Text = Format(ADD_Inc_DATE_TXT.Text, "dd/mm/yyyy")
End If
End Sub
Private Sub Calendar2_Click()
TXT_AssetMgr_DATE = CalendarForm.GetDate
If IsDate(ADD_Inc_DATE_TXT.Text) Then
Me.TXT_AssetMgr_DATE.Text = Format(TXT_AssetMgr_DATE.Text, "dd/mm/yyyy")
End If
End Sub
Private Sub Calendar3_Click()
TXT_LastUserDATE = CalendarForm.GetDate
If IsDate(ADD_Inc_DATE_TXT.Text) Then
Me.TXT_LastUserDATE.Text = Format(TXT_LastUserDATE.Text, "dd/mm/yyyy")
End If
End Sub
Private Sub Calendar4_Click()
ADD_Date_ServiceJobLogged_TXT = CalendarForm.GetDate
If IsDate(ADD_Inc_DATE_TXT.Text) Then
Me.ADD_Date_ServiceJobLogged_TXT.Text = Format(ADD_Date_ServiceJobLogged_TXT.Text, "dd/mm/yyyy")
End If
End Sub
‘Under Private Sub UserForm_Initialize() I have the following date related code:
Private Sub UserForm_Initialize()
Me.ADD_Date_Recorded_TXT.value = Format(Now, "dd/mm/yyyy") ‘ this works perfectly (correct format is returned)
Me.ADD_Time_Recorded_TXT.Text = Format(Now(), "HH:mm")
‘***Note: my system date is dd/mm/yyyy and in the spreadsheet cells, the format is set to dd/mm/yyyy
Use this code in the form's code module (right click the text box, "View code"):
Private Sub ADD_Inc_DATE_TXT_AfterUpdate()
TxT_SWIRL_DueDate.Value = Format(DateAdd("m", 1, CDate(ADD_Inc_DATE_TXT.Value)),"dd/mm/yyyy")
End Sub
I recommend useing the AfterUpdate event, as the Change event fires every time the value in the textbox gets changed - eg also while typing. This only fires when the user has finished typing, and moved to the next tiem on the form (clicks somewhere else).
Also consider using some form of date control instead of textbox control. There are quite a few out there, and depending on the Excel version you are using, you may only be able to use a select few of those.