Worksheet value is updated only after userform is closed

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
On my worksheet in two cells should be customers name & the date.
The two cells in question only get the values entered after the userform is closed.
Take a look at text in Red

This is the code in use.
VBA Code:
Private Sub PurchasedKey_Click()
  Dim sPath As String
  Dim strFileName As String
  Dim sh As Worksheet
 
  If ComboBox1 = "" Then
  MsgBox "YOU DID NOT ENTER A CUSTOMERS NAME", vbCritical, "NO NAME ENTERED ON SHEET"
  ComboBox1.SetFocus
  Exit Sub
    
  End If
 
[COLOR=rgb(184, 49, 47)]  With ThisWorkbook.Worksheets("PRINT LABELS")
    .Range("B3") = Me.ComboBox1.Text
    .Range("E3") = Format(DateSerial(CLng(Me.cboYear.Value), Me.cboMonth.ListIndex + 1, Me.cboDay.Value), "long date")
    
  End With[/COLOR]
  Unload PrinterForm
                                                                            
  With ActiveSheet
    If .Range("P1") = "" Then
      MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
      Exit Sub
    End If
    If .Range("N1") = "M" Then
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & " " & .Range("P1").Value & " (SLS).pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    Else

    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & ".pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    End If

    With ActiveSheet
    ActiveWindow.SelectedSheets.PrintOut copies:=1
    
    MsgBox "DONT FORGET TO HYPERLINK CUSTOMER ON POSTAGE SHEET", vbInformation, "HYPERLINK DISCO II KEY MESSAGE"
 
 End With
 End With
End Sub

I also tried this thinking when i select a value in the ComboBox the change would then do it but NO.

Code:
Private Sub ComboBox1_Change()
    ComboBox1 = UCase(ComboBox1)
    
    If ComboBox1.Value > 0 Then
    PurchasedKey.Visible = True
    PurchasedCode.Visible = True
    End If
    
    ThisWorkbook.Worksheets("PRINT LABELS").Range("B3").Value = PrinterForm.ComboBox1.Value
End Sub

The values do get entered but seems pointless the way it currently works
 
I thought you were asking how is the form opened so I showed you. So it’s not new code but just advising how form is open.

You need to be more patient with me saying you won’t ask the question again, who writes that ????
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Me. Who doesn't answer a basic question after 5 posts? Who doesn't bother to augment information by doing simple searches when they don't understand a concept? Surely if you can post a thread on Mr. Excel you can pose a question to Google instead of replying with 'don't know what you mean'.

Now you'll be upset with me so I figure the best I can do for you is to stay out of your threads going forward.

Wish you luck though.
 
Upvote 0
What if you include "Application.Calculate" after the line where you think the values should be entered?
 
Upvote 0
I have tried the Application.Calculate but it made no difference.
I also tried the advice from previous member but also no difference.

My workflow is as follows.

First worksheet i have a userform where various values are entered.
Once completed the userform closes, the next worksheet is activated & another userform opens.
This is the userform that had an issue or the issue this post is about.

I decided to put the code / text boxes etc on the first sheets userform.

All works fine & worksheet is now showing values in worksheet cells as it should of done.

Many thanks for the input here.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top