runtime error 1004

Fred Evans

Board Regular
Joined
Apr 22, 2015
Messages
60
Hello Everyone
I wrote a macro which is supposed to change the fill color of a cell- but when I run the macro
i get the error "runtime error 1004 application defined or object defined error"

what is it trying to tell me and how do i get the thing to work??

This is the macro
Code:
Sub blueme()
'
' blueme Macro
' Makes blue fill in cell
'
' Keyboard Shortcut: Ctrl+b
'
    ActiveCell.Offset(-2, -22).Range("A1").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub




thanks

fred from south africa
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Fred,

If the active cell (whatever is selected before you run the code) is not in column "W" (or further to the right) your offset (-2, -22) tries to select a cell that is off the sheet. Negative row or column numbers are not allowed. It will also fail if you are in row 1 or 2. Can you better explain what you are trying to do?

Gary
 
Upvote 0
Ok thats interesting.
Now this macro was created by the process of recording the macro in the development
tab . where would this offset have come from ??
(regarding what I was trying to do - I want alt q to change the fill of a cell to a different colour.
I rewrote the macro and it works OK now)
thanks for the feedback
 
Upvote 0
where would this offset have come from ??

It's hard to say. I often look at recorded code and wonder why it adds lots of extra code. In lieu of clairvoyance, the developers were just trying to cover as many angles as they could.

Glad you got it working.
 
Last edited:
Upvote 0
Thanks Gary-
Could it be that the cursor happened to be in that cell when the macro was recorded??


I like your signature -- a nice development of it could be
"If absolutely nothing can go wrong then something will go wrong and if everything possible could go wrong
then everything possible will go wrong
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top