Worksheet value is updated only after userform is closed

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,596
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You didn't say if you open the userform modal or not. If modal, I don't think you'll see the form values on the sheet until you close the form. I was going to suggest to use a control's value property rather than text, but since neither works I'm assuming your form is modal. BTW, value is the default so just about 99.9% of cases, you don't need to write it.
 
Upvote 0
I forgot to suggest that your alternative would be to open the form as not modal and see if that fixes it.
You had an opportunity to clear up the modal/not modal issue but... :unsure:
we/I are still guessing about that.
 
Upvote 0
I tried both and could always see the value entered on the sheet with user form visible
 
Upvote 0
Not sure what you mean by MODAL ?

See attached 2 screenshots.

You will see nothing entered in cells but when i close form the cells are then shown with the values
 

Attachments

  • EaseUS_2024_07_ 5_21_01_30.jpg
    EaseUS_2024_07_ 5_21_01_30.jpg
    103.3 KB · Views: 9
  • EaseUS_2024_07_ 5_21_01_54.jpg
    EaseUS_2024_07_ 5_21_01_54.jpg
    61.3 KB · Views: 11
Upvote 0
Not sure what you mean by MODAL
Whenever I'm faced with ambiguity like that, I use a search engine. Much of the time, it's better than asking in a forum since often, the topic is complicated or maybe just diverse. You tend to learn more than what you get in a quick post reply.
 
Upvote 0
This is how the form is open.


Rich (BB code):
  Application.ScreenUpdating = True
  
  ActiveWorkbook.Save
  
  With Sheets("PRINT LABELS")
  .Activate
  .Range("A1").Select
  .Range("Q1").Value = Range("E5").Value & Range("F5").Value & Range("G5").Value & Range("H5").Value & Range("I5").Value & Range("J5").Value
  
  
  End With
  PrinterForm.Show
End Sub
 
Upvote 0
Just cant see why ????

Look at screenshot please.
I process a file.
I see the message that pdf has been created.
At this point you will see that no name or date etc is placed in the cells shown by red arrow.
I go to the folder & yep the file is there & the values are shown fine.

So now i select OK to the onscreen message.
Now the customers name & date are shown.

How or why is the generated file shown correctly BUT the sheet cells dont even shown anything until after i select OK ?

When i make a selection from the ComboBox im expecting the cells on the worksheet to be then filled or am i missing something.
 

Attachments

  • EaseUS_2024_07_ 5_21_30_11.jpg
    EaseUS_2024_07_ 5_21_30_11.jpg
    96 KB · Views: 10
Last edited:
Upvote 0
Now you're showing different code. In the newest code post, remove the .Activate for the sheet. I still say it's because your form is opened modal but you can try removing that line first. Activation or selection of anything is almost never warranted. For the modal issue, put the form in design view, look at the property sheet.
1720214342777.png


Sorry, but I won't be raising this question again.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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