My original problem was: VBA do not make any computation during the run (copying, pasting, applying formulas) even when calculations are automatically defined, and even when screenUpdating
is True
then since I export out a PDF it seems to be with missing data. Only until I close the userform
it makes all computations. So a trick was unload Userform1
which works but is odd.
Private Sub CommandButton1_Click()
'some code for button1 on userform1 which should be already executed when I hit button2
End Sub
Public Sub CommandButton2_Click()
'this sub routine hide userform1 to userform2 and make more calculations
If UserForm1.ComboBox1.ListIndex <> -1 Then
'TextBox16.Value = ListBox2.Column(0, ListBox2.ListIndex)
Dim hFile As Workbook
Set hFile = ThisWorkbook
Dim rng1, rng2, rng3, rng4, rng44, rng5, rng6, rng7, rng8 As Range
Dim rngPM, rngDM, rngSE, rngH, rngW As Range
Set rng1 = hFile.Sheets("Promedio-Movil").Range("D6:D17") 'real 2019
Set rngPM = hFile.Sheets("Promedio-Movil").Range("I6") 'real ene 20
Set rng2 = hFile.Sheets("Movil-Doble").Range("D6:D17") 'real 2019
UserForm1.Hide
UserForm2.Show 'HERE THE PROBLEM, THIS SHOULD BE AT THE START
ActiveWorkbook.Sheets("Datos").Select
If UserForm1.ComboBox1.ListIndex = 0 Then
'Aguja-Espinal'
Range("B3:B14").Copy
rng4.PasteSpecial Paste:=xlPasteValues ' real 2018 holt
End If
'some more code to print PDF
End Sub
The problem it's precisely that in the code above, I was using set
and other codes before I change from userform1
to userform2
to say I did the change in the middle of the code, but changing to the start now works as expected.
'some more code using set here
Set rng8 = hFile.Sheets("DescomposicionSeries").Range("C2:C9")
UserForm1.Hide
UserForm2.Show 'these two lines to the start of the Sub routine