ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB.net select column and format (https://www.excelbanter.com/excel-programming/438988-vbulletin-net-select-column-format.html)

irishrose

VB.net select column and format
 
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,

Chip Pearson

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,



All times are GMT +1. The time now is 07:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com