Afternoon Guys,
I am completely new to VB but have managed to write something that is on the verge of being useful to me.
The Issue I have is that existing date data that I have, displays in Excel as 29/09/2012 for example, however if I copy and paste special, formula I find that the actual format is 41181. (I am sure there are better ways of finding this out and explaining it).
Now to my question.
My Form date text box, requests the user type the date as dd/mm/yyyy. This is then inserted in to a Cell as hard text 29/09/2012.
This creates an issue with graphing the data.
My question is. How can I code so that VB accepts the date in the format dd/mm/yyyy, inserts it into a Cell as the date format 41181 (Serial Date?) and still displays the date as dd/mm/yyyy ???
I hope someone understands this and has solved this problem before.
I have pasted my code below for your entertainment
Private Sub CMDAddNext_Click()
'Adds entered data into Sheet 1'
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Cells(LastRow, 1).Value = tb_Date.Value
Cells(LastRow, 2).Value = tb_Depth.Value
Cells(LastRow, 3).Value = tb_RL.Value
Cells(LastRow, 4).Value = tb_Remarks
'Clears Form Data'
tb_Date.Text = ""
tb_Depth.Text = ""
tb_RL.Text = ""
tb_Remarks.Text = ""
End Sub
Private Sub CMDGraph_Click()
'Opens Worksheet "Graph" and Closes Form'
Sheets("Graph (Water Level RL)").Select
Unload Me
End Sub
Private Sub tb_Date_AfterUpdate()
'Checks Date is in desired Format. Will accept dd/mm/yyyy and mm/dd/yyyy'
If IsDate(Format(tb_Date.Text, "dd/mm/yyyy")) = False Then MsgBox "Please Enter A Valid Date"
End Sub
Private Sub tb_Depth_Change()
'Calculates the RL of the water based on RL 1211.38 - Data Inserted in Depth to Water'
tb_RL = ((1211.38) - Val(tb_Depth))
End Sub
Private Sub UserForm_Click()
End Sub
This code works beautifully for what I need and although I am sure there are better ways please do not rewrite the code. It would be a waste of your time.
Thanks for your help.
I am completely new to VB but have managed to write something that is on the verge of being useful to me.
The Issue I have is that existing date data that I have, displays in Excel as 29/09/2012 for example, however if I copy and paste special, formula I find that the actual format is 41181. (I am sure there are better ways of finding this out and explaining it).
Now to my question.
My Form date text box, requests the user type the date as dd/mm/yyyy. This is then inserted in to a Cell as hard text 29/09/2012.
This creates an issue with graphing the data.
My question is. How can I code so that VB accepts the date in the format dd/mm/yyyy, inserts it into a Cell as the date format 41181 (Serial Date?) and still displays the date as dd/mm/yyyy ???
I hope someone understands this and has solved this problem before.
I have pasted my code below for your entertainment
Private Sub CMDAddNext_Click()
'Adds entered data into Sheet 1'
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Cells(LastRow, 1).Value = tb_Date.Value
Cells(LastRow, 2).Value = tb_Depth.Value
Cells(LastRow, 3).Value = tb_RL.Value
Cells(LastRow, 4).Value = tb_Remarks
'Clears Form Data'
tb_Date.Text = ""
tb_Depth.Text = ""
tb_RL.Text = ""
tb_Remarks.Text = ""
End Sub
Private Sub CMDGraph_Click()
'Opens Worksheet "Graph" and Closes Form'
Sheets("Graph (Water Level RL)").Select
Unload Me
End Sub
Private Sub tb_Date_AfterUpdate()
'Checks Date is in desired Format. Will accept dd/mm/yyyy and mm/dd/yyyy'
If IsDate(Format(tb_Date.Text, "dd/mm/yyyy")) = False Then MsgBox "Please Enter A Valid Date"
End Sub
Private Sub tb_Depth_Change()
'Calculates the RL of the water based on RL 1211.38 - Data Inserted in Depth to Water'
tb_RL = ((1211.38) - Val(tb_Depth))
End Sub
Private Sub UserForm_Click()
End Sub
This code works beautifully for what I need and although I am sure there are better ways please do not rewrite the code. It would be a waste of your time.
Thanks for your help.