ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create a public variable (https://www.excelbanter.com/excel-programming/436706-create-public-variable.html)

ordnance1[_2_]

Create a public variable
 
Below is my UserForm_Initialize code. What I'm wondering is, is it possible
to declare a Public Variable if rng(1, 7).value is "Yes"?

I would call the Variable Cleared and then during my exit routine
(clicking the Finished Button) I would need a statement that said if Cleared
is true then exit sub.



Private Sub UserForm_Initialize()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)

TextBox1.Value = rng(1, 1) 'Date
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yyyy")
TextBox2.Value = rng(1, 2) 'Check Number
TextBox3.Value = rng(1, 3) 'Check Amount
TextBox3.Value = Format(TextBox3.Value, "currency")
TextBox4.Value = rng(1, 4) 'Paid To
TextBox5.Value = rng(1, 5) 'Explination

If rng(1, 7).Value = "Yes" Then
OptionButton1.Value = True
End If

End Sub


joel[_271_]

Create a public variable
 

You need to put the public statement in a module outside any function or
sub. Like this


Public Joel1

Sub Test
Userform1.Show
end Test


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=157596

Microsoft Office Help


Ryan H

Create a public variable
 
This should help. If this helps please click "YES" below.

If rng(1, 7).Value = "Yes" Then
Public Cleared As Boolean
Cleared = True
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub
--
Cheers,
Ryan


"ordnance1" wrote:

Below is my UserForm_Initialize code. What I'm wondering is, is it possible
to declare a Public Variable if rng(1, 7).value is "Yes"?

I would call the Variable Cleared and then during my exit routine
(clicking the Finished Button) I would need a statement that said if Cleared
is true then exit sub.



Private Sub UserForm_Initialize()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)

TextBox1.Value = rng(1, 1) 'Date
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yyyy")
TextBox2.Value = rng(1, 2) 'Check Number
TextBox3.Value = rng(1, 3) 'Check Amount
TextBox3.Value = Format(TextBox3.Value, "currency")
TextBox4.Value = rng(1, 4) 'Paid To
TextBox5.Value = rng(1, 5) 'Explination

If rng(1, 7).Value = "Yes" Then
OptionButton1.Value = True
End If

End Sub

.


Bob Phillips

Create a public variable
 
Did you actually try that?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Ryan H" wrote in message
...
This should help. If this helps please click "YES" below.

If rng(1, 7).Value = "Yes" Then
Public Cleared As Boolean
Cleared = True
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub
--
Cheers,
Ryan


"ordnance1" wrote:

Below is my UserForm_Initialize code. What I'm wondering is, is it
possible
to declare a Public Variable if rng(1, 7).value is "Yes"?

I would call the Variable Cleared and then during my exit routine
(clicking the Finished Button) I would need a statement that said if
Cleared
is true then exit sub.



Private Sub UserForm_Initialize()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)

TextBox1.Value = rng(1, 1) 'Date
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yyyy")
TextBox2.Value = rng(1, 2) 'Check Number
TextBox3.Value = rng(1, 3) 'Check Amount
TextBox3.Value = Format(TextBox3.Value, "currency")
TextBox4.Value = rng(1, 4) 'Paid To
TextBox5.Value = rng(1, 5) 'Explination

If rng(1, 7).Value = "Yes" Then
OptionButton1.Value = True
End If

End Sub

.




Ryan H

Create a public variable
 
No, Bob. I didn't. Thanks for the correction. It should be.

'in standard module
Public Cleared As Boolean

If rng(1, 7).Value = "Yes" Then
Cleared = True
Else
Cleared = False
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub

--
Cheers,
Ryan


"Bob Phillips" wrote:

Did you actually try that?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Ryan H" wrote in message
...
This should help. If this helps please click "YES" below.

If rng(1, 7).Value = "Yes" Then
Public Cleared As Boolean
Cleared = True
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub
--
Cheers,
Ryan


"ordnance1" wrote:

Below is my UserForm_Initialize code. What I'm wondering is, is it
possible
to declare a Public Variable if rng(1, 7).value is "Yes"?

I would call the Variable Cleared and then during my exit routine
(clicking the Finished Button) I would need a statement that said if
Cleared
is true then exit sub.



Private Sub UserForm_Initialize()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)

TextBox1.Value = rng(1, 1) 'Date
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yyyy")
TextBox2.Value = rng(1, 2) 'Check Number
TextBox3.Value = rng(1, 3) 'Check Amount
TextBox3.Value = Format(TextBox3.Value, "currency")
TextBox4.Value = rng(1, 4) 'Paid To
TextBox5.Value = rng(1, 5) 'Explination

If rng(1, 7).Value = "Yes" Then
OptionButton1.Value = True
End If

End Sub

.



.


Rick Rothstein

Create a public variable
 
If rng(1, 7).Value = "Yes" Then
Cleared = True
Else
Cleared = False
End If


Or, more concisely, replace the above with this single line of code...

Cleared = rng(1, 7).Value = "Yes"

--
Rick (MVP - Excel)


"Ryan H" wrote in message
...
No, Bob. I didn't. Thanks for the correction. It should be.

'in standard module
Public Cleared As Boolean

If rng(1, 7).Value = "Yes" Then
Cleared = True
Else
Cleared = False
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub

--
Cheers,
Ryan


"Bob Phillips" wrote:

Did you actually try that?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Ryan H" wrote in message
...
This should help. If this helps please click "YES" below.

If rng(1, 7).Value = "Yes" Then
Public Cleared As Boolean
Cleared = True
End If

Sub FinishedButton_Click()
If Cleared Then Exit Sub
End Sub
--
Cheers,
Ryan


"ordnance1" wrote:

Below is my UserForm_Initialize code. What I'm wondering is, is it
possible
to declare a Public Variable if rng(1, 7).value is "Yes"?

I would call the Variable Cleared and then during my exit routine
(clicking the Finished Button) I would need a statement that said if
Cleared
is true then exit sub.



Private Sub UserForm_Initialize()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)

TextBox1.Value = rng(1, 1) 'Date
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yyyy")
TextBox2.Value = rng(1, 2) 'Check Number
TextBox3.Value = rng(1, 3) 'Check Amount
TextBox3.Value = Format(TextBox3.Value, "currency")
TextBox4.Value = rng(1, 4) 'Paid To
TextBox5.Value = rng(1, 5) 'Explination

If rng(1, 7).Value = "Yes" Then
OptionButton1.Value = True
End If

End Sub

.



.




All times are GMT +1. The time now is 01:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com