VB.net select column and format


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?

1/29/2010 5:05:01 PM
excel.programming 6508 articles. 2 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 53

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

Dim RangeToFormat As Excel.Range
Dim WS As Excel.Worksheet
RangeToFormat = DirectCast( _
    XLApp.Workbooks("Book1.xls"). _
    Worksheets.Item("Sheet1"), Excel.Worksheet). _
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.

Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
[email on web site]

On Fri, 29 Jan 2010 09:05:01 -0800, irishrose
<irishrose@discussions.microsoft.com> wrote:

>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?
1/29/2010 9:12:50 PM

Similar Artilces:

Conditional formatting / formulas
I set up a table with a list of states in one column and amount of tons in another column (ex from the book). I set up a conditional format in a cell above the table to highlight all similar states when entered in the above cell; ex: when I type IOWA, all IOWA listings will be highlighted in the list. Then I tried a formula next to that one that will add all the tons for each of the highlighted states. I looked on the Internet and found a formula using MATCH but it only entered the amount from the first IOWA, not the rest. Does anyone have any idea how I would write that formula. Would I use ...

VB distmon?
Hi I have recently installed Office 2003. A couple of wired things happen in Excel: > Everytime I close the program I get a MS VB error that reads "Compile error in hidden module: Distmon" Every time open the program I get the same error, but the macro it is calling is "autoexecnew" > Since my new installation, I type in an simple function like TRIM and it tells me cannot find project library. any ideas? Thnaks! Alan Alan http://support.microsoft.com/default.aspx?scid=kb;EN-US;q307410 OFF: "Compile Error in Hidden Module" Error Message When You Sta...

How do I change a word's style and not select the whole word?
In PowerPoint, I can change a word's style (to bold, italics, or underline) simply by clicking somewhere in the word and then clicking on the style I want. However, in Word, I have to highlight the entire word in order to change the style. Is there a way to click in the word and change the style without having to select the whole word first? Tools > Options > Edit (Word 2007 - Word Options > Advanced > Editing Options) - check 'When selecting automatically select entire word'. -- <>>< ><<> ><<> <>>< >&l...

CRichEditCtrl + selection(shift + end)
hi in my application i am doing syntax highlighting. currently i am able to color the keywords. but there is one problem. if i select this portion of keyword (which is in blue color) with keyboard (shift + End) then the color get's vanished.in contrast if i select the same text with mouse then it does not disturb. why something like this is happening? is the selection with keyboard and mouse are different in functionaliy? If anybody know's please suggest some solution. CRichEditCtrl creation code is like this m_rich.Create(ES_AUTOVSCROLL |ES_AUTOHSCROLL | ES_NOHIDESEL | ES_MULTILI...

Excel VB
I have two cells in a workbook that are dates. The cell Start_Date has a valid date in it. The second cell Test_Date is either blank or has a valid date in it. The IsDate test on both cells works fine, however, on a blank cell the Month function extracts "12". Anyone know why? I had to put the month function within a test for IsDate to make it work. Seems like Month function on a blank cell should return something other than a 12. Dave Test code: If IsDate(Range("Start_Date")) Then 'Cell has 11/01/09 in it. MsgBox ("start date a d...

data selected is not what appears on the chart
I am trying to change the range of data but the information I am selecting is not what is showing up on the chart. Right-click on the chart, and select "Source Data". Look at what is in your data series. -- David Biddulph "JJ" <JJ@discussions.microsoft.com> wrote in message news:2730EF4A-9575-41D5-958F-9C360CFAF4EA@microsoft.com... >I am trying to change the range of data but the information I am selecting >is > not what is showing up on the chart. ...

Download NET 3.5 Sp1 Service Pack
I can't download the NET 3.5 Service Pack3 or Service Pack 2. I have XP They do not exist - there is only Dot Net Fx 3.5 SP1. "marlsrsoftball" <marlsrsoftball@discussions.microsoft.com> wrote in message news:49BC29A3-F9B1-430B-B5EE-C4DA5B6C0E95@microsoft.com... >I can't download the NET 3.5 Service Pack3 or Service Pack 2. > > I have XP What it is saying ".NET 3.5 Service Pack 1 Framwork not installed when I try to dowload it i get an Error Code: 0x80070645 Fred "Jerry" wrote: > They do not exist - there is...

Cannot Add any window to VB
Hello: I'm using a VM with GP 10.0 SP3 installed. In order to have the same as our production databases i copy the GP folder, entirely, which i think it was a mistake now I'm getting a "This cannot be added to Visual Basic", whenever i try to add a window, any window, to VB. Also it goes without saying that there's a lot of load errors starting GP. For the record the copy/paste thing worked, sort of, and before you start thinking that i was insane to have done this, there's a reason behind it, There's been a lot of tweaks to our production server, by our p...

Word's Formatting Palette
I've worked with Word in Windows and Mac equally. There are features in both that are wanting in the other. In Word for Windows, the Formatting Palette is a wonderfully accessible window that can be made as large as screen real estate allows. In Word for Mac, the Formatting Palette is a tiny fixed-sized window that offers few advantages over the menu bar. This is just one of many features I hope to see improved in Office 2008. Frequently, I wonder if the developers actually use the applications they work on and if there is any exchange between Windows and Mac developers. If a function ...

macro which looks in column and if it is blank deletes entire row
macro which looks in column and if it is blank deletes entire row if sny row in column A is blank , macro deletes entire row thanks appreciate u al -- Message posted from http://www.ExcelForum.com Since this is very often asked question, it might be a good time to use the archives or Ron's excellent add in http://www.rondebruin.nl/ -- Don Guillett SalesAid Software donaldb@281.com "vikram >" <<vikram.15j1kg@excelforum-nospam.com> wrote in message news:vikram.15j1kg@excelforum-nospam.com... > macro which looks in column and if it is blank deletes ent...

Selecting & copying a named range through a listbox
When i click on a button i want a listbox to pop up. In this listbox there has to appear a list with named ranges. The named range which is selected in this listbox has to be copied Can somenone give me some code for this. That's it ! Thanxxx, Luc Since your post is kinda vague I will have to ask some questions and makes some assumptions. 1.) Are you wanting to select multiple ranges to be copied from a listbox or select a single range to be copied from a combobox? 2.) Where do you want the range copied to? Another worksheet, workbook, somewhere else withi...

Free Workshop on .NET and Programming Solutions by Dr. Venkat
Those of us programming on the .NET framework have come to realize the power and increased productivity that comes with it, says Dr. Venkat Submramaniam. Like any development, however, there are things that one should pay attention to while programming on .NET. Are there things in .NET that, if we do not pay attention to, may result in more trouble than it is worth? Learn all there is to know in a FREE video workshop conducted by Dr. Venkat Subramaniam. In the workshop recorded at Saltmarch Media's Great Indian Developer Summit, Venkat presents Gotchas that a developer needs ...

Conditional Formatting 04-06-10
Is it possible to conditionally format a cell that has a value of #DIV/ 0? I don't think so. You can signal any error condition by using ISERROR(A1), or just ISERR(A1) if you don't care about #NA errors, as your Conditional Formatting formula, but I don't think you can narrow it down to just the #DIV/0! error. I would think you should be able to use Event code to mimic the behavior of Conditional Formatting if a VB solution is acceptable. -- Rick (MVP - Excel) "hotplate" <hotplate74@gmail.com> wrote in message news:228e8431-a8b8-4150-8ba2-02...

format cells #2
I'm trying to format a cell in a spreadsheet that was sent to my office. When I click on "format cells...", nothing happens. I've never had this problem before. What gives? It sounds like the worksheet may be protected. I'm guessing "Cells" under "Format" is dimmed, meaning it is unavailable. Try: Tools > Protection If the choices include "Unprotect Sheet...", then it was protected, in which case, clicking on "Unprotect Sheet..." will disable the protection and you should be able to format to your heart's content. Regards...

vb from VC++
Hi, is it possible, and if so, to call a Vb macro from VC++. Or manipulate spreadsheets (ie draw graphs from the data within the workbooks) usinbg MFC functions cheers Anthony Presumably you are referring to MS Excel spreadsheets and workbooks. The easiest method would be to import the appropriate type library (.tlb) provided with Excel, having the class wizard generate the classes, which you then use to access the Excel Automation model (that is the same model that Excel VBA uses). Some investigation may be needed to determine which tlb to use, and to make sure you have a basic understand...

VB in Excel
In Excel I go into Visual Basic Editor, then Visual Basic Help, but when I type 'Passwords' for example it will bring up a list of related items, but some of them you can't select. Does this mean the installation CD is corrupt and hasn't installed all the components? I have reinstalled and repaired the installtion but to no avail. Any ideas anyone? Help! Thanks ...

help with format / formula
in C2, 2 choices (menu) Single or Multiple single refers to cells B8:D12 multiple to cells G9:J13 Until a choice is made both sets of cells remain blanked out (white text using conditional format) When a choice is made then that set of cells would show as black letters (using conditional format) but only the range of cells that the choice (single or multiple) refers to. Is it possible to achieve the above with conditional formatting. thanks "SS" <nonense50@blueyonder.co.uk> wrote in message news:MclUo.49596$WK5.27065@newsfe28.ams2... > in C2, 2 choices (menu)...

Is there some function in Excel (VBA) that will get me the column alphabet if I provide the column number, or do I have to write one. I ask because I know that there is, yet I recall I wrote this functionality for the previous application, and I don't want to: (1) Reuse it, if there's something in-built (2) Re-invent the wheel Help! PS: I'm looking for something like: code:-------------------------------------------------------------------------------- Function GetAlphabet(ByVal ColumnNumber as Long) as String ------------------------------------------------------------------...

Sheet selection on Autoclose
Hi all, i was wondering whether if anyone can help me on this problem. I have this macro that protects the spreadsheet at worksheet and workbook level when i close spreadsheet, however, i discovered a problem when i have mutiple spreadsheets opened together with this particular sheet and exiting excel all together at once. The macro instead of targeting and running the macro for the worksheet it opened with, will just work for top-most opened spreadsheet which i am closing from. I do not want to hardcode the name of the spreadsheet into the macro as this is a generic macros t...

Find and replace with formatting
I am using Excel 2000. I have a large range of numbers and need to identify if numbers entered in a separate, smaller range are included in the large range and then change the format of only the included numbers so that they are easily identifiable to users looking at the large range. There are more and more numbers being manually added weekly to the smaller range. I hope this makes sense, I have tried using macros but can't seem to get anywhere near. Thanks for reading this. "Del" <anonymous@discussions.microsoft.com> wrote in message news:071701c3b4c7$55113af0...

Random selection #2
How can I set a random selection based on a set number of records in Excel, without repeating the selected record? I have a column with a list of individual names and another column with list of countries. I want to randomly select a country in the 2nd column and assign it to the person's name in the 1st column. However, once the first selection is made I cannot use that country name again for the second selection, and so on. An example that describes what I want to do is when we select names from a hat for gift exchange during holidays. It is a set of specific names, and they will no...

I'm trying to have a balance column
Why does this not work? =SUM(B4-(E4-G4-I4-K4-M4)) I want to subtract the values in the parens from the value in B4. Thanks for your help I fingered it out, thanks! =SUM(B4-(E4+G4+I4+K4+M4)) "drumz" wrote: > Why does this not work? > =SUM(B4-(E4-G4-I4-K4-M4)) > I want to subtract the values in the parens from the value in B4. > Thanks for your help You don't need to use SUM. =B4-(E4+G4+I4+K4+M4) will do. Francis Hayes http://www.TheExcelAddict.com =b4-sum(e4,g4,i4,k4,m4) best wishes Gabor Sebo "drumz" <drumz@discussions...

Conditional Formatting #31
Hello I would like to use a Check for Underline in conditional formatting, is it possible andwhat is the syntax for the command Robin AFAIK, there's no way to check for whether an underline has been applied without using VBA. You could use this UDF: Public Function CheckForUnderline(Optional rCell As Range) As Boolean Application.Volatile If rCell Is Nothing Then Set rCell = Application.Caller(1) CheckForUnderline = Not _ rCell.Font.Underline = xlUnderlineStyleNone End Function Then in your CF: Formula is =CheckForUnderline(A1) Not...

VB.Net program to create XML file
I need to create an xml file from a VB program using fields returned from an sql query. I have a template that was provided for me and need to use verbatim. Since this is just a text file, I gather that I can just write out the file with all of the tags, etc., and name it .xml. Assuming that is correct what I might want to do is create a template so that if this file changes the names of the elements, all I have to do is change the template and if more elements get added I can then add them. Is there a tool that can do this for me? If I have to create one, any suggestions as to what I ...

Selecting across worksheets
How do I select across worksheets within a file? I want to select across worksheets and view the accumulating total at the bottom of the worksheet. =SUM(Sheet1!:Sheet3!A3) -- HTH RP (remove nothere from the email address if mailing direct) "JMS" <JMS@discussions.microsoft.com> wrote in message news:15A369D1-561E-4616-B0EB-0FA36A703566@microsoft.com... > How do I select across worksheets within a file? > > I want to select across worksheets and view the accumulating total at the > bottom of the worksheet. ...