View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default VB.net select column and format

What sort of formatting do you mean? The basic code would be something
like

Dim RangeToFormat As Excel.Range
Dim WS As Excel.Worksheet
RangeToFormat = DirectCast( _
XLApp.Workbooks("Book1.xls"). _
Worksheets.Item("Sheet1"), Excel.Worksheet). _
Range("A1").EntireColumn
WS = RangeToFormat.Worksheet
RangeToFormat = _
XLApp.Intersect(WS.UsedRange, RangeToFormat)
RangeToFormat.Font.Bold = True

This sets the variable RangeToFormat to that portion of column F that
resides within the used range of the worksheet "Sheet1" in workbook
"Book1.xls". Once it has that range object, it applies a Bold format
to the text font. If your module uses Option Strict On (and you should
be doing that), you need the DirectCast on the worksheet. If you have
Option Strict Off in effect, you don't need the DirectCast.

If this code does not suffice, please post back with much more detail
about what you are trying to do, the code you have now that doesn't
work, and an explanation of what you want to accomplish.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Fri, 29 Jan 2010 09:05:01 -0800, irishrose
wrote:

Hi,

I am using VB.net 2005 with Excel 2003. I need to select a single column
and apply formating to it. Can someone please explain how to do this?

Thanks,