ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform/Cell formatting (https://www.excelbanter.com/excel-programming/278202-userform-cell-formatting.html)

Todd Huttenstine

Userform/Cell formatting
 
I had to change the offsets from 0, 0 to 1, 0 and it
worked perfectly. But what is the code I would use if I
wanted it set up like I had before (see below)....

like this:
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value

and when I type a number in one of the textboxes, it
automatically adds a % on it and shows that % while in the
text box.

Also the userform1.hide code at the end doesnt actually
close the userform. What is the code I would use to have
it unload the form so next time I open it up, the changes
are automatically reflected.


Thanx.

Private Sub CommandButton2_Click()
Dim i As Long, sStr As String
With Worksheets("Pay Calculator").Range("AA1")
For i = 1 To 4
sStr = Me.Controls("TextBox" & i).Value
If InStr(sStr, "%") Then
.Offset(i - 1, 0).Value = sStr
Else
.Offset(i - 1, 0).Value = CDbl(sStr) / 100
End If
Next
End With
UserForm1.Hide
End Sub


-----Original Message-----
Private Sub CommandButton2_Click()
Dim i as Long, sStr as String
With Worksheets("Pay Calculator").Range("AA1")
for i = 1 to 4
sStr = Me.Controls("TextBox" & i).Value
if instr(sStr,"%") then
.offset(i-0,0).Value = sStr
Else
.offset(i-0,0).Value = cdbl(sStr)/100
End if
Next
End With
Userform1.Hide
End Sub

--
Regards,
Tom Ogilvy

Todd Huttenstine

wrote in message
...
Below is code that inserts the value of the specified
textbox into the specified cell.

Private Sub CommandButton2_Click()
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value
Worksheets("Pay Calculator").Range("AA2").Value =
TextBox2.Value
Worksheets("Pay Calculator").Range("AA3").Value =
TextBox3.Value
Worksheets("Pay Calculator").Range("AA4").Value =
TextBox4.Value
UserForm1.Hide
End Sub

I have formatted the cells in percentages rounded off

to 2
decimal places. For instance if I were to enter 10
directly in the cell, the cell would show 10%. So now

if
I were to enter 10 in TextBox1, I want it to put 10% in
cell AA1, instead it puts 1000% in the cell, however if

I
were to enter 10% in TextBox1, it then puts 10% in cell
AA1 which is what I want, but I dont want to have to

type
the % in.

Is there a way I can make it to where no matter what is
typed in the text box it will automatically have the %

on
the end of the number in the textbox. Or is it possible
to when I type in a number in the textbox without a % on
the end, it will automatically put 10% in the cell?

What
is the code for these 2 methods?

Thank you.



.


Tom Ogilvy

Userform/Cell formatting
 
Unload Userform1

or

Unload Me

--
Regards,
Tom Ogilvy

Todd Huttenstine wrote in message
...
I had to change the offsets from 0, 0 to 1, 0 and it
worked perfectly. But what is the code I would use if I
wanted it set up like I had before (see below)....

like this:
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value

and when I type a number in one of the textboxes, it
automatically adds a % on it and shows that % while in the
text box.

Also the userform1.hide code at the end doesnt actually
close the userform. What is the code I would use to have
it unload the form so next time I open it up, the changes
are automatically reflected.


Thanx.

Private Sub CommandButton2_Click()
Dim i As Long, sStr As String
With Worksheets("Pay Calculator").Range("AA1")
For i = 1 To 4
sStr = Me.Controls("TextBox" & i).Value
If InStr(sStr, "%") Then
.Offset(i - 1, 0).Value = sStr
Else
.Offset(i - 1, 0).Value = CDbl(sStr) / 100
End If
Next
End With
UserForm1.Hide
End Sub


-----Original Message-----
Private Sub CommandButton2_Click()
Dim i as Long, sStr as String
With Worksheets("Pay Calculator").Range("AA1")
for i = 1 to 4
sStr = Me.Controls("TextBox" & i).Value
if instr(sStr,"%") then
.offset(i-0,0).Value = sStr
Else
.offset(i-0,0).Value = cdbl(sStr)/100
End if
Next
End With
Userform1.Hide
End Sub

--
Regards,
Tom Ogilvy

Todd Huttenstine

wrote in message
...
Below is code that inserts the value of the specified
textbox into the specified cell.

Private Sub CommandButton2_Click()
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value
Worksheets("Pay Calculator").Range("AA2").Value =
TextBox2.Value
Worksheets("Pay Calculator").Range("AA3").Value =
TextBox3.Value
Worksheets("Pay Calculator").Range("AA4").Value =
TextBox4.Value
UserForm1.Hide
End Sub

I have formatted the cells in percentages rounded off

to 2
decimal places. For instance if I were to enter 10
directly in the cell, the cell would show 10%. So now

if
I were to enter 10 in TextBox1, I want it to put 10% in
cell AA1, instead it puts 1000% in the cell, however if

I
were to enter 10% in TextBox1, it then puts 10% in cell
AA1 which is what I want, but I dont want to have to

type
the % in.

Is there a way I can make it to where no matter what is
typed in the text box it will automatically have the %

on
the end of the number in the textbox. Or is it possible
to when I type in a number in the textbox without a % on
the end, it will automatically put 10% in the cell?

What
is the code for these 2 methods?

Thank you.



.




Todd Huttenstine

Userform/Cell formatting
 
Thank you. I was doing userform1.unload. I wondered why
it wasnt working.

Thanx again.


-----Original Message-----
Unload Userform1

or

Unload Me

--
Regards,
Tom Ogilvy

Todd Huttenstine

wrote in message
...
I had to change the offsets from 0, 0 to 1, 0 and it
worked perfectly. But what is the code I would use if I
wanted it set up like I had before (see below)....

like this:
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value

and when I type a number in one of the textboxes, it
automatically adds a % on it and shows that % while in

the
text box.

Also the userform1.hide code at the end doesnt actually
close the userform. What is the code I would use to

have
it unload the form so next time I open it up, the

changes
are automatically reflected.


Thanx.

Private Sub CommandButton2_Click()
Dim i As Long, sStr As String
With Worksheets("Pay Calculator").Range("AA1")
For i = 1 To 4
sStr = Me.Controls("TextBox" & i).Value
If InStr(sStr, "%") Then
.Offset(i - 1, 0).Value = sStr
Else
.Offset(i - 1, 0).Value = CDbl(sStr) / 100
End If
Next
End With
UserForm1.Hide
End Sub


-----Original Message-----
Private Sub CommandButton2_Click()
Dim i as Long, sStr as String
With Worksheets("Pay Calculator").Range("AA1")
for i = 1 to 4
sStr = Me.Controls("TextBox" & i).Value
if instr(sStr,"%") then
.offset(i-0,0).Value = sStr
Else
.offset(i-0,0).Value = cdbl(sStr)/100
End if
Next
End With
Userform1.Hide
End Sub

--
Regards,
Tom Ogilvy

Todd Huttenstine

wrote in message
...
Below is code that inserts the value of the specified
textbox into the specified cell.

Private Sub CommandButton2_Click()
Worksheets("Pay Calculator").Range("AA1").Value =
TextBox1.Value
Worksheets("Pay Calculator").Range("AA2").Value =
TextBox2.Value
Worksheets("Pay Calculator").Range("AA3").Value =
TextBox3.Value
Worksheets("Pay Calculator").Range("AA4").Value =
TextBox4.Value
UserForm1.Hide
End Sub

I have formatted the cells in percentages rounded off

to 2
decimal places. For instance if I were to enter 10
directly in the cell, the cell would show 10%. So

now
if
I were to enter 10 in TextBox1, I want it to put 10%

in
cell AA1, instead it puts 1000% in the cell, however

if
I
were to enter 10% in TextBox1, it then puts 10% in

cell
AA1 which is what I want, but I dont want to have to

type
the % in.

Is there a way I can make it to where no matter what

is
typed in the text box it will automatically have the

%
on
the end of the number in the textbox. Or is it

possible
to when I type in a number in the textbox without a

% on
the end, it will automatically put 10% in the cell?

What
is the code for these 2 methods?

Thank you.



.



.



All times are GMT +1. The time now is 04:14 PM.

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