Force Userform textbox to text only format

buzz71023

Active Member
Joined
May 29, 2011
Messages
282
I have a userform that has various codes that are beingmistaken by excel as date format or something and it keeps changing my formatautomatically.
The few of the code types are below.

1
2
3-5
3-17
3-23
3-61
7-81
7-86

How can I get these to stop changing when the userform macroexecutes and places the data in the cell?
Below is what I am using in the userform to input this data.

Code:
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Public TypeHrRNG As Range[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]
Private Sub UserForm_Activate()[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]        
          Set TypeHrRNG =Cells(ActiveCell.Row, "I")[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000][FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]          txtHOURS =TypeHrRNG.Value[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub
[/COLOR][/SIZE][/FONT]


And then the button that executes the button
Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub CommandButton3_Click()[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]        TypeHrRNG = txtHOURS.Value[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]        Unload Me[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000]       ActiveCell.Rows("1:" &Selection.Rows.Count).EntireRow.EntireRow.AutoFit[/COLOR][/SIZE][/FONT]

[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][SIZE=3][COLOR=#000000]      Range("a17").Select[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub

[/COLOR][/SIZE][/FONT]

Open to any and all ideas.

Thanks in advance.
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,185
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
TypeHrRNG.NumberFormat = "@"
TypeHrRNG = txtHOURS.Value
 

buzz71023

Active Member
Joined
May 29, 2011
Messages
282
Thank you.
I actually figured out I had another issue going on. I couldn't locate it, so I just erased it all and then rebuilt it and it worked.

Thank you for your reply.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,185
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,260
Messages
5,769,091
Members
425,516
Latest member
Melzebu

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
Top