getting runtime error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using VBA to format a workbook. Part of the formatting includes copying
a page and renaming it. This works fine. Then I return to original page to
add some formatting. This works fine. Then I am trying to return to the
second page and add some formatting. But I am getting a runtime error on the
first "range" line. The chart that I am trying to go to is the "Standard
Chart Data" page and I want to add text to D1.
Sheets("Standard Chart Data").Select
Range("D1").Select
ActiveCell.FormulaR1C1 = "Mean"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Plus 2sd"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Minus 2sd"
Range("I1").Select

Any ideas?
TIA
 
I don't see anything obviously wrong with your code. I would point out
though that you can eliminate a lot of unneeded code and moving around like
this:

With Sheets("Standard Chart Data")
.Range("D1").Value = "Mean"
.Range("E1").Value = "Plus 2sd"
.Range("F1").Value = "Minus 2sd"
End With

This doesn't bother to select the sheet or any cells since it can directly
modify cells without it.
--
Jim Rech
Excel MVP

|I am using VBA to format a workbook. Part of the formatting includes
copying
| a page and renaming it. This works fine. Then I return to original page
to
| add some formatting. This works fine. Then I am trying to return to the
| second page and add some formatting. But I am getting a runtime error on
the
| first "range" line. The chart that I am trying to go to is the "Standard
| Chart Data" page and I want to add text to D1.
| Sheets("Standard Chart Data").Select
| Range("D1").Select
| ActiveCell.FormulaR1C1 = "Mean"
| Range("E1").Select
| ActiveCell.FormulaR1C1 = "Plus 2sd"
| Range("F1").Select
| ActiveCell.FormulaR1C1 = "Minus 2sd"
| Range("I1").Select
|
| Any ideas?
| TIA
 
That worked wonderfully. Thanks for helping me streamline my code.
I appreciate it very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top