LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Error code 91

The followng block of code is producing Error Code 91 while dealing with the
variable "Length".

This code is ran against a verticle colum of text data that is either 1, 2,
3 or 4 characters in length and is numbers stored as text. The range
selected is typically the entire column. My ultimate goal here is to add the
necassary code that will add the appropriate number of leading zeros so that
all the data is 4 characters long.





Sub ConfigureTimeData()
' Counts Characters in Text String then runs code depending on Character
Count
Dim FormulaCells As Range, ConstantCells As Range
Dim Cell As Range
Dim Length As Double
Length = Cell.Characters.Count
If TypeName(Selection) < "Range" Then Exit Sub
Application.ScreenUpdating = False

' Create subsets of original selection to avoid processing empty cells
On Error Resume Next
Set FormulaCells = Selection.SpecialCells(xlFormulas, xlNumbers)
Set ConstantCells = Selection.SpecialCells(xlConstants, xlTextValues)

On Error GoTo 0

' Process the formula cells
If Not FormulaCells Is Nothing Then
For Each Cell In FormulaCells
If Cell.Value < 2 Then
Cell.Interior.Color = RGB(0, 0, 0)

Else
Cell.Interior.Color = RGB(122, 100, 0)
End If
Next Cell
End If

' Process the constant cells
If Not ConstantCells Is Nothing Then
For Each Cell In ConstantCells
Select Case Length
Case 0
Exit Sub
Case 1
Cell.Interior.Color = RGB(255, 0, 0)
Case 2
Cell.Interior.Color = RGB(0, 255, 0)
Case 3
Cell.Interior.Color = RGB(0, 0, 255)
Case 4
Cell.Interior.Color = RGB(50, 0, 0)
Case Is 5
Cell.Interior.Color = RGB(255, 0, 255)
End Select



Next Cell
End If
End Sub

 
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
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
OnTime code error "can't execute code in break mode" tskogstrom Excel Programming 1 September 8th 06 10:29 AM
Error in Excel VBA Code (Error 91) dailem Excel Programming 1 August 25th 06 03:45 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 07:11 PM.

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"