Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

userform not behave expected

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Userform will not behave as expected

Userform will not behave as expected

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Change the Print button so it brings up the Print dialogue box

If you want to bring up the Print dialogue box to check your print settings when you hit the Print button, do the following:

1. Right-click on the toolbar that displays the Print button.

2. Select Customise.

3. Click on the Print button on the toolbar to select it, then hold the left mouse button down and drag the button towards the screen below. The button should come off the toolbar.

4. In the Customise dialogue box on your screen, select the Commands tab.

5. Select File from the Categories list, and then locate the Print... icon (looks like the normal Print button, but the word Print has three dots following it).

6. Click on the Print... icon to select it, then use your left mouse to drag and drop the icon onto the toolbar at the top of the screen.

7. Close the Customise dialogue box.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.