?
Solved

Attempting to select a specific Excel sheet and work with Cell ranges to write and format the data

Posted on 2011-02-24
2
Medium Priority
?
296 Views
Last Modified: 2012-05-11
I am attempting to select a specific Excel sheet within my Excel VBA Code. In selecting say "Sheet2" I am writing Excel headers and would also like, etc. like this
With oExcel.Sheets(1)
End With
The problem is that since the .Range and .Selection properties are on the same level as .Sheets property, I can't seem to work with Sheet2 like I need to as in the code below. I'm sure there's a way to get around this but I haven't figured it out yet.

Thank you for your help Experts!
Wallace
With oExcel
        .Range("A3", "A54").Select
        .Selection.Interior.ColorIndex = 1
        .Selection.Font.Name = "Tahoma"
        .Selection.Font.ColorIndex = 2
        .Selection.Font.Size = 10
        .Selection.Font.Italic = True
    End With

Open in new window

0
Comment
Question by:wally_davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 34974832
With oExcel
   With .Sheets("Sheet1")
        With .Range("A3", "A54")
            .Interior.ColorIndex = 1
            .Font.Name = "Tahoma"
            .Font.ColorIndex = 2
            .Font.Size = 10
            .Font.Italic = True
       End With
    End With
End With

Kevin
0
 

Author Closing Comment

by:wally_davis
ID: 34981053
Perfect solution Kevin! Thank you very much.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question