Strange Userform date problem

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
773
Office Version
  1. 2016
Platform
  1. Windows
I have a range of cells formatted so that the dates show as # symbols as the columns are narrow. Which is what I want.

My Userform includes txtboxes as dates. It pulls the data from the cells no problem. But when I press my replace button. It pastes the data back into the correct cell but the dates are now visible no matter how narrow the columns. Obviously the dates overlap in adjacent cells.

If I press F2 and enter the cells go back to the correct format.

It’s got me stumped.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Please post the code for your Replace button. It should be something like:

ActiveCell.Value = DateValue(TextBox1.Text)

At the moment a text string that looks like a date is being transferred to the worksheet.
 
Upvote 0

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
773
Office Version
  1. 2016
Platform
  1. Windows
Thanks for the help.

I've taken out a few rows for different textboxes to shrink it down a bit.

I didn't write the code, I only modified it to suit my needs.

Private Sub cmdReplace_Click()

Dim NumRepl
Dim NNumRepl
Dim NBARepl
Dim NPriceRepl

Dim NtestRepl

Dim r As Range



Dim BARepl As String
Dim PriceRepl As String
Dim NameRepl As String
Dim faddress As String


Dim testRepl As String



With Me
NameRepl = .Listbox1.Column(0)
NumRepl = .Listbox1.Column(1)
NNumRepl = .txtProductNumber
BARepl = .Listbox1.Column(2)
NBARepl = .txtBA
PriceRepl = .Listbox1.Column(3)
'New------------------------------------------------------
testRepl = .Listbox1.Column(4)





'New--------------------------------------------------
NtestRepl = .txttest



NPriceRepl = .txtPrice
End With

With Sheets("Staff_Database").Range("ProductRange")
Set r = .Find(What:=NameRepl, LookAt:=xlValue, MatchCase:=False)
If Not r Is Nothing Then
faddress = r.Address
Do
'New-----------------------------------------------------
If r.Offset(0, 1) = NumRepl _
And r.Offset(0, 2) = BARepl _
And r.Offset(0, 3) = PriceRepl _
And r.Offset(0, 4) = testRepl


r = Me.txtDescription
r.Offset(0, 1) = NNumRepl
r.Offset(0, 2) = NBARepl
r.Offset(0, 3) = NPriceRepl

r.Offset(0, 4) = NtestRepl

Exit Do
End If
Set r = .FindNext(r)
Loop While Not r Is Nothing And r.Address <> faddress
Else
MsgBox "This Name Has Not Been Found, Please Try Again", vbInformation + vbOKOnly, "Name Not Found"
Me.txtSearch = ""
Me.txtSearch.SetFocus
End If
End With
With Me
.txtSearch.Value = ""
.txtBA.Value = ""
.txtDescription.Value = ""
.txtPrice.Value = ""
.txtProductNumber.Value = ""
'New-------------------------------------------------------
.txttest.Value = ""

.Listbox1.Clear
.cmbAdd.Enabled = True
.cmdSearch.Enabled = True
.cmdDelete.Enabled = False
.cmdReplace.Enabled = False
End With
End Sub
 
Upvote 0

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
773
Office Version
  1. 2016
Platform
  1. Windows
Really sorry about that.

It's, txttest
 
Upvote 0

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
773
Office Version
  1. 2016
Platform
  1. Windows
I'm afraid it didn't work. Would I need to change every occurance of the line within the whole module?
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,436
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
you need to change it where you write the value to the sheet:
Code:
r.Offset(0, 4) = CDate(NtestRepl)
 
Upvote 0

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
773
Office Version
  1. 2016
Platform
  1. Windows
I'm afrid it hasn't worked. It turns this line yellow:

NhoursRepl = DateValue(.txthours.Value)

Am I doing something wrong?
 
Upvote 0

Forum statistics

Threads
1,191,719
Messages
5,988,287
Members
440,148
Latest member
sandy123

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