Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Interior class error/runtime error 1004

Hi,
I've written some code that alters the interior of a cell colour based on
certain criteria. The code works fine in Excel 2003 but in Excel 97 I
sometimes get runtime error 1004 relating to the Interior class. I do need
it to work in excel 97.

I run the Excel 97 on a laptop running Windows 98, and Excel 2003 on my
desktop running win xp pro service pack 2.
The problem code is as follows:

Sub AgeCriteriaChecker()
Dim CellsToBeChecked As Range 'this is the range that contains the ages
Set CellsToBeChecked = Range(Range("C2"), Range("C65536").End(xlUp))
Dim i , Age As Integer

For i = 1 To CellsToBeChecked.Cells.Count
Age = CellsToBeChecked.Cells(i).Value

Select Case Age
Case 20 To 34
CellsToBeChecked.Cells(i, 2).Interior.Color = vbRed
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2

Case 35 To 49
CellsToBeChecked.Cells(i, 2).Interior.Color = vbCyan
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
Case 50 To 65
CellsToBeChecked.Cells(i, 2).Interior.Color = vbYellow
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
Case Else
CellsToBeChecked.Cells(i, 2).Interior.Color = vbBlack
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
End Select

Next i
End Sub


Any help is greatly appreciated

Many thanks
David





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Interior class error/runtime error 1004

Do you run this code from a commandbutton from the control toolbox toolbar? Or
any control from that toolbar?

If yes, try changing the .takefocusonclick property to false for that
commandbutton. (under rightclick properties).

If it's a control that doesn't have that .takefocusonclick property, you can
add:

activecell.activate

at the top of your code.

(In fact, this'll work for the commandbutton, too.)

It's a bug in xl97 that was fixed in xl2k.



David Goodall wrote:

Hi,
I've written some code that alters the interior of a cell colour based on
certain criteria. The code works fine in Excel 2003 but in Excel 97 I
sometimes get runtime error 1004 relating to the Interior class. I do need
it to work in excel 97.

I run the Excel 97 on a laptop running Windows 98, and Excel 2003 on my
desktop running win xp pro service pack 2.
The problem code is as follows:

Sub AgeCriteriaChecker()
Dim CellsToBeChecked As Range 'this is the range that contains the ages
Set CellsToBeChecked = Range(Range("C2"), Range("C65536").End(xlUp))
Dim i , Age As Integer

For i = 1 To CellsToBeChecked.Cells.Count
Age = CellsToBeChecked.Cells(i).Value

Select Case Age
Case 20 To 34
CellsToBeChecked.Cells(i, 2).Interior.Color = vbRed
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2

Case 35 To 49
CellsToBeChecked.Cells(i, 2).Interior.Color = vbCyan
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
Case 50 To 65
CellsToBeChecked.Cells(i, 2).Interior.Color = vbYellow
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
Case Else
CellsToBeChecked.Cells(i, 2).Interior.Color = vbBlack
CellsToBeChecked.Cells(i, 2).Font.ColorIndex = 2
End Select

Next i
End Sub

Any help is greatly appreciated

Many thanks
David


--

Dave Peterson

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
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
Runtime Error '1004' - AddFields method of PivotTable class failed MikeC[_3_] Excel Programming 1 May 21st 04 06:58 AM
RUNTIME ERROR '1004' --- Select method of worksheet class failed jawee Excel Programming 2 April 30th 04 06:47 AM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM


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