Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro storing as a date?

Hi,
I need some help with this macro. When I run it I get the yellow explanation mark on some cells in column D which I formatted as text. It says a date string is represented with only two digits for the year. This is not date information but pure text. How to I tell Excel 2003 that column D is not a date?
Thanks,
Wes

Basically you enter numbers into column A and run the macro. This highest number is recorded in B and the lowest in C with a concatenation in D of B/C. Enter new values in A and run it again etc.

Sub HiLo()
Dim LastRow As Long, i As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
' if cells A < B (or B empty) then B = A (highest value)
If .Range("A" & i) < .Range("B" & i) Or IsEmpty(.Range("B" & i)) Then
.Range("B" & i) = .Range("A" & i).Value
End If
' if cells A B then B = A (lowest value)
If .Range("A" & i) .Range("C" & i) Then
.Range("C" & i) = .Range("A" & i).Value
End If
'concatenate cells B & C into D
.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)
Next
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Macro storing as a date?

On Saturday, March 9, 2013 7:34:36 PM UTC-8, Wes Finch wrote:
Hi,

I need some help with this macro. When I run it I get the yellow explanation mark on some cells in column D which I formatted as text. It says a date string is represented with only two digits for the year. This is not date information but pure text. How to I tell Excel 2003 that column D is not a date?

Thanks,

Wes



Basically you enter numbers into column A and run the macro. This highest number is recorded in B and the lowest in C with a concatenation in D of B/C. Enter new values in A and run it again etc.



Sub HiLo()

Dim LastRow As Long, i As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row

For i = 1 To LastRow

' if cells A < B (or B empty) then B = A (highest value)

If .Range("A" & i) < .Range("B" & i) Or IsEmpty(.Range("B" & i)) Then

.Range("B" & i) = .Range("A" & i).Value

End If

' if cells A B then B = A (lowest value)

If .Range("A" & i) .Range("C" & i) Then

.Range("C" & i) = .Range("A" & i).Value

End If

'concatenate cells B & C into D

.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)

Next

End With

End Sub



Give this a try.

..Range("D" & i) = "'" & .Range("B" & i) & "/" & .Range("C" & i)

Regards,
Howard
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro storing as a date?

It work great!
Why does adding a null to the start of the string correct this?
Thanks Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Macro storing as a date?

On Sunday, March 10, 2013 6:38:43 AM UTC-7, Wes Finch wrote:
It work great!

Why does adding a null to the start of the string correct this?

Thanks Howard



By concatenating a number with a null string, the number converts to text.
And once it is text Excel stops trying to "help" you when you don't want or need it.

My guess is that the "auto-assumption" to convert certain values to dates came first and then came the "cure" from the deep dark programming rooms in Redmond Washington.

Regards,
Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro storing as a date?

On Saturday, March 9, 2013 11:50:20 PM UTC-5, Howard wrote:
On Saturday, March 9, 2013 7:34:36 PM UTC-8, Wes Finch wrote:

Hi,




I need some help with this macro. When I run it I get the yellow explanation mark on some cells in column D which I formatted as text. It says a date string is represented with only two digits for the year. This is not date information but pure text. How to I tell Excel 2003 that column D is not a date?




Thanks,




Wes








Basically you enter numbers into column A and run the macro. This highest number is recorded in B and the lowest in C with a concatenation in D of B/C. Enter new values in A and run it again etc.








Sub HiLo()




Dim LastRow As Long, i As Long




With ActiveSheet




LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row




For i = 1 To LastRow




' if cells A < B (or B empty) then B = A (highest value)




If .Range("A" & i) < .Range("B" & i) Or IsEmpty(.Range("B" & i)) Then




.Range("B" & i) = .Range("A" & i).Value




End If




' if cells A B then B = A (lowest value)




If .Range("A" & i) .Range("C" & i) Then




.Range("C" & i) = .Range("A" & i).Value




End If




'concatenate cells B & C into D




.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)




Next




End With




End Sub






Give this a try.



.Range("D" & i) = "'" & .Range("B" & i) & "/" & .Range("C" & i)



Regards,

Howard


Sorry Howard I did not test it hard enough. In some instances it is still reverting to a date.

Wes


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Macro storing as a date?

Hi Wes,

Am Sun, 10 Mar 2013 11:42:53 -0700 (PDT) schrieb Wes Finch:

I did not test it hard enough. In some instances it is still reverting to a date.


try:
..Range("D" & i).NumberFormat = "@"
..Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro storing as a date?

On Sunday, March 10, 2013 1:52:55 PM UTC-5, Claus Busch wrote:
Hi Wes,



Am Sun, 10 Mar 2013 11:42:53 -0700 (PDT) schrieb Wes Finch:



I did not test it hard enough. In some instances it is still reverting to a date.




try:

.Range("D" & i).NumberFormat = "@"

.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Thanks Claus,
But no that does not work either.
Wes
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Macro storing as a date?


Thanks Claus,

But no that does not work either.

Wes


Hi Wes,

Are you still having a problem with this? If so, give us a few samples of the numbers that are giving you trouble. I tried Claus' idea, worked great for me.

regards,

Dave
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Macro storing as a date?

Hi Wes,

Am Sun, 10 Mar 2013 11:42:53 -0700 (PDT) schrieb Wes Finch:

I did not test it hard enough. In some instances it is still
reverting to a date.


try:
.Range("D" & i).NumberFormat = "@"
.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)


Regards
Claus Busch


I find that this works better after the value has been entered...

.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)
.Range("D" & i).NumberFormat = "@"

...but using the apostrophe as suggested by Howard obviates having to
specify NumberFormat.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Macro storing as a date?

Hi Garry,

Am Mon, 18 Mar 2013 00:09:48 -0400 schrieb GS:

I find that this works better after the value has been entered...

.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)
.Range("D" & i).NumberFormat = "@"


the formatting as text first should avoid changing the entered value to
a date. If the entered value already changed to a date, a later
formatting as text gives a wrong result.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Macro storing as a date?

Hi Garry,

Am Mon, 18 Mar 2013 00:09:48 -0400 schrieb GS:

I find that this works better after the value has been entered...

.Range("D" & i) = .Range("B" & i) & "/" & .Range("C" & i)
.Range("D" & i).NumberFormat = "@"


the formatting as text first should avoid changing the entered value
to a date. If the entered value already changed to a date, a later
formatting as text gives a wrong result.


Regards
Claus Busch


Thanks, Claus! I'll take a closer look at this as I was probably
thinking something else...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Macro storing as a date?

Found it! I was in an entirely different context. My apologies...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing date and time Noepie Excel Programming 2 February 10th 09 09:10 PM
Storing data in Short Date format TESA0_4 New Users to Excel 2 July 22nd 08 01:25 AM
Storing a Macro name in a Variable Jack Adams Excel Programming 2 October 5th 04 03:59 PM
storing an equation in a macro sowetoddid[_8_] Excel Programming 5 April 26th 04 10:35 PM
storing numbers within the macro Chris Excel Programming 0 October 27th 03 06:04 PM


All times are GMT +1. The time now is 09:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"