-
May 7th, 2014, 01:29 PM
#1
Thread Starter
New Member
Run-time 1004 error
Please HELP!
I just tried to make my very first record macro ever. when i attempted to run it I received a run-time 1004 error. I clicked debug, and it pulled up and highlighted a line.... below is a clip of the part that apparently causes the error, I have changed the font color to red and increased the font size of the line the debugger highlighted. does anyone know how I can fix this??
Code:
Range("J27:R28").Select
Range("J28").Activate
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 24
Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 18
Selection.ShapeRange.IncrementLeft 66.3461417323
Selection.ShapeRange.IncrementTop 47.3077165354
Selection.ShapeRange.ScaleHeight 2.3951682469, msoFalse, _
msoScaleFromBottomRight
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"" & Chr(13) & "" & Chr(13) & "" & Chr(13) & "NOT FOR" & Chr(13) & "CONSTRUCTION"
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 1). _
ParagraphFormat
.FirstLineIndent = 0
.Alignment = msoAlignCenter
Last edited by Siddharth Rout; May 7th, 2014 at 04:21 PM.
-
May 7th, 2014, 04:24 PM
#2
Re: Run-time 1004 error
Two Main reasons why `.Select`/`.Activate`/`Selection`/`Activecell`/`Activesheet`/`Activeworkbook` etc... should be avoided
1. It slows down your code.
2. It is usually the main cause of runtime errors.
How do we avoid it?
1) Directly work with the relevant objects
Consider this code
Code:
Sheets("Sheet1").Activate
Range("A1").Select
Selection.Value = "Blah"
Selection.NumberFormat = "@"
This code can also be written as
Code:
With Sheets("Sheet1").Range("A1")
.Value = "Blah"
.NumberFormat = "@"
End With
2) If required declare your variables. The same code above can be written as
Code:
Dim ws as worksheet
Set ws = Sheets("Sheet1")
With ws.Range("A1")
.Value = "Blah"
.NumberFormat = "@"
End With
Similarly for the shapes.
HTH
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|