Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Moving down one cell

Here is what I use. It converts the entire selected range (to a maximum of
the used range). I keep this in an addin which is accessed via a menu bar.

Private Const m_MaxYear As Integer = 2099
Private Const m_MinYear As Integer = 1970

Private Sub Convert()
On Error GoTo ErrorHandler
Dim rngCurrent As Range
Dim rngToSearch As Range

Set rngToSearch = Intersect(ActiveSheet.UsedRange, Selection)
If Not rngToSearch Is Nothing Then
Application.Calculation = xlCalculationManual
For Each rngCurrent In rngToSearch
If Left(rngCurrent.Value, 1) < "=" Then
If Len(rngCurrent) = 8 And ValidMonth(rngCurrent) And
ValidYear(rngCurrent) Then
rngCurrent.NumberFormat = "mm/dd/yy"
rngCurrent.Value = CDate(rngCurrent.Value)
End If

End If
Next

End If

ErrorHandler:
Application.Calculation = xlCalculationAutomatic
End Sub

Private Function ValidMonth(ByVal rngCurrent As Range) As Boolean
Dim blnReturnValue As Boolean

blnReturnValue = False
Select Case UCase(Left(rngCurrent.Value, 3))
Case "JAN"
blnReturnValue = True
Case "FEB"
blnReturnValue = True
Case "MAR"
blnReturnValue = True
Case "APR"
blnReturnValue = True
Case "MAY"
blnReturnValue = True
Case "JUN"
blnReturnValue = True
Case "JUL"
blnReturnValue = True
Case "AUG"
blnReturnValue = True
Case "SEP"
blnReturnValue = True
Case "OCT"
blnReturnValue = True
Case "NOV"
blnReturnValue = True
Case "DEC"
blnReturnValue = True
End Select

ValidMonth = blnReturnValue

End Function

Private Function ValidYear(ByVal rngCurrent As Range) As Boolean
Dim blnReturnValue As Boolean
Dim intYear As Integer

If IsNumeric(Right(rngCurrent.Value, 4)) Then
intYear = CInt(Right(rngCurrent.Value, 4))
If intYear m_MinYear And intYear < m_MaxYear Then
blnReturnValue = True
Else
blnReturnValue = False
End If
Else
blnReturnValue = False
End If

ValidYear = blnReturnValue

End Function
--
HTH...

Jim Thomlinson


"Jordan" wrote:

I have a date listed as APR 2005 or Mar 2005. If I format the column as a
date it doesnt change until I press F2 and hit enter and then it shows as
04/01/2005 or 03/01/2005. Which is what I want.

Can anyone tell me how what code to use to tell it to press F2, hit enter
and then move down one cell until it reaches a blank cell.

Or is there a way to re-calculate all the cells without having to open them?

Thanks in advance for any help you can give me.

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
Arrow keys moving whole excel sprdsht insted of from cell to cell Ms-Exl-Learner New Users to Excel 2 December 17th 09 07:20 AM
Moving cell contents to new cell loses background color in old cel John Excel Discussion (Misc queries) 4 May 11th 09 01:56 AM
Arrows not moving from cell to cell, when I push arrow columns m Luanne Excel Discussion (Misc queries) 2 December 11th 08 07:24 PM
Arrow keys move screen instead of moving from cell to cell. JaJay777 Setting up and Configuration of Excel 1 January 17th 05 06:48 PM
How to copy formatting when moving from cell to variable to another cell on another worksheet kls[_2_] Excel Programming 1 September 11th 04 10:42 PM


All times are GMT +1. The time now is 06:52 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"