Force Userform textbox to text only format

buzz71023

Active Member
Joined
May 29, 2011
Messages
280
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:

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Fluff

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

buzz71023

Active Member
Joined
May 29, 2011
Messages
280
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
42,669
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,102,367
Messages
5,486,443
Members
407,547
Latest member
Sankarasrinivas

This Week's Hot Topics

Top