98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Userform will not behave as expected
Userform will not behave as expected
Resolved · High Priority · Version 2016
Diane has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Excel VBA Advanced course
Userform will not behave as expected
Is there a method to attach a file along with this question? Without it it is impossible to demonstrate I think. So the problem I have is that I have created a userform. It behaves properly if I have the focus on one worksheet, but not correctly when I have it on another worksheet. My problem is the one it will not work on is the one I need it to work on. I have spent days looking at this to no avail and tried my things. The incorrect behaviour is that a row which should be written to the worksheet will not appear until the cancel button is selected and yet the exact same code will show the row as written on an alternative spreadsheet. I cannot find any reason for this and it is driving me to distraction. Here is the code from the USerform
The worksheet is question is set in wsHoliday. It will work correctly if I set the worksheet to ws5 (which in fact is not holiday at all), but if I change that one thing on this code and point it to worksheet 3, which is the holiday worksheet then it works in a limited fashion (doesn't error) but does not behave as I need it to.
Private Sub cmdOK_Click()
Dim emptyRow As Long
Dim lNextRow As Long
Dim rFindPerson As Range
Dim wsPR, wsHoliday As Worksheet
Set wsPR = Sheets(1) 'pr
Set wsHoliday = Sheets(5) '
lNextRow = WorksheetFunction.CountA(wsHoliday.Range("A:A")) + 1
If IsNull(lstSelectPerson) Then
MsgBox "Please select a name"
GoTo finish
End If
'Transfer information
On Error GoTo message
Set rFindPerson = wsPR.Range("x:x").Find(what:=lstSelectPerson.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not rFindPerson Is Nothing Then
'Debug.Print rFindPerson.Address & rFindPerson.Value
wsHoliday.Cells(lNextRow, 1) = wsPR.Cells(rFindPerson.Row, 1).Value
wsHoliday.Cells(lNextRow, 4) = txtSdate.Value
wsHoliday.Cells(lNextRow, 5) = txtEdate.Value
If chkHalfDay.Value = True Then wsHoliday.Cells(lNextRow, 6).Value = ".5"
End If
GoTo finish:
message:
MsgBox "didn't find you"
finish:
'deselect person name
Me.lstSelectPerson.Value = ""
End Sub
RE: Userform will not behave as expected
Hi Diane,
Thank you for the forum question and I hope that you are fine.
Yes it is probably a good idea that I see the file.
You can send it to:
info@stl-training.co.uk
Please just type in the subject "question for Jens" then I will get it.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Screen Splitters in ExcelScreen splitter icons can be set from the ribbon bar, or dragged from the scroll bars. The icon just above the up arrow on the right scroll bar controls the horizontal splitter; the icon to the right of the right arrow on the bottom scroll bar controls the vertical splitter. |