finaljustice
Board Regular
- Joined
- Oct 6, 2010
- Messages
- 175
Hi there,
I am having a simple issue, I am not being able to call a sub that is in another userform.
On userform1 I have this sub I use to load information to the userform.
(It was before declared as Private, but I thought if I declared it as Public It would solve the problem)
Then on another userform2, I have a command button which called 2 subs like so:
Só I remembered that I used this mechanism when the code was on a module, therefore I removed the "loadresults" from userform1 and pasted it in module 1 and declared it public. Like so:
It now works...
I would like to know why is it that I can't have a Public sub inside the userform folder?
Thanks for your time.
I am having a simple issue, I am not being able to call a sub that is in another userform.
On userform1 I have this sub I use to load information to the userform.
(It was before declared as Private, but I thought if I declared it as Public It would solve the problem)
Code:
Public Sub loadresults() 'simply reload results and is located is in the userform1.
UserForm1.TextBox1 = Format(ThisWorkbook.Sheets("LD").Range("W28"), "Standard")
UserForm1.TextBox2 = Format(ThisWorkbook.Sheets("LD").Range("P412"), "Standard")
UserForm1.TextBox3 = Format(ThisWorkbook.Sheets("LD").Range("J15"), "Standard")
UserForm1.TextBox4 = Format(ThisWorkbook.Sheets("LD").Range("J18"), "Standard")
UserForm1.TextBox5 = Format(ThisWorkbook.Sheets("LD").Range("I22"), "Standard")
UserForm1.TextBox6 = Format(ThisWorkbook.Sheets("LD").Range("J22"), "Standard")
End Sub
Then on another userform2, I have a command button which called 2 subs like so:
Code:
Private Sub CommandButton1_Click() 'this is in userform2 EditMP 'this code is in userform2 and calls fine
loadresults 'this code is in userform1 and gives me an error.
End Sub
Só I remembered that I used this mechanism when the code was on a module, therefore I removed the "loadresults" from userform1 and pasted it in module 1 and declared it public. Like so:
Code:
Public Sub loadresults() 'simply reload results, saved on a module not a userform.
UserForm1.TextBox1 = Format(ThisWorkbook.Sheets("LD").Range("W28"), "Standard") 'Custo para Lingotamento
UserForm1.TextBox2 = Format(ThisWorkbook.Sheets("LD").Range("P412"), "Standard") 'Balanço térmico
UserForm1.TextBox3 = Format(ThisWorkbook.Sheets("LD").Range("J15"), "Standard") '% ressopro P
UserForm1.TextBox4 = Format(ThisWorkbook.Sheets("LD").Range("J18"), "Standard") 'indice de projeçao
UserForm1.TextBox5 = Format(ThisWorkbook.Sheets("LD").Range("I22"), "Standard") 'rendimento Fe do Conversor Prelimiar
UserForm1.TextBox6 = Format(ThisWorkbook.Sheets("LD").Range("J22"), "Standard") 'rendimento Fe do Conversor Real
End Sub
It now works...
I would like to know why is it that I can't have a Public sub inside the userform folder?
Thanks for your time.