DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: change row colors in excel

  1. #1
    Join Date
    Apr 2010

    change row colors in excel

    okay so i have this code

    Dim oexcel As Microsoft.Office.Interop.Excel.Application
    Dim obook As Microsoft.Office.Interop.Excel.Workbook
    Dim osheet As Microsoft.Office.Interop.Excel.Worksheet

    oexcel = New Microsoft.Office.Interop.Excel.Application
    obook = oexcel.Workbooks.Open("c:\test\test.xls")
    osheet = obook.Worksheets(1)

    Dim LastRow As Integer = osheet.UsedRange.Rows.Count
    osheet.Range("A" & LastRow.ToString + 1).Value = Date.Now
    osheet.Range("B" & LastRow.ToString + 1).Value = TextBox1.Text

    oexcel = Nothing

    this code basically writes rows to an excel sheet not overwriting any row but systematically enters new lines every time the button is pressed. each row has a column for type of visit i.e. appointment, new, rush

    what i want to do is fill the rows with different colors for example if column "B" on whatever row says appointment i want the whole row to be red. ive never had to program the color of an excel row and could use some help! thanks in advance!!

  2. #2
    Join Date
    Feb 2004
    Longueuil, Québec
    The best way to learn how to do something when working with Excel is to have Excel record a macro that does the operation.

    You can do that by calling Tools...Macro...Record New macro.

    You perform the operation, setting the color of a row in your case.

    You click the Stop Recording Button in the small toolbar that was created when you started the recording. If the toolbar is not visible, you can stop the recording through Tools...Macro.

    You then Switch to the VBA editor with Alt-F11. In the VBAProject window in the upper left, you should find a module that contains the recorded macro. The Object.Method necessary to perform the operations you did while recording will be there in plain sight. You only have to adjust them to the variables you used in your .NET code.
    Jacques Bourgeois

Similar Threads

  1. change Excel Cell Forecolor using VB6
    By Lennie in forum VB Classic
    Replies: 1
    Last Post: 08-17-2008, 02:24 AM
  2. Replies: 0
    Last Post: 03-09-2006, 09:40 PM
  3. Previous & Next Record
    By nickiii in forum .NET
    Replies: 2
    Last Post: 07-01-2005, 12:03 PM
  4. ANN: Active XL Report 4.1 - Excel reporting with practically no coding
    By Alexander Frolov [Afalina Co., Ltd.] in forum vb.announcements
    Replies: 0
    Last Post: 06-24-2002, 12:13 PM
  5. Getting the row id of a row in SQL Server 4.2 and 7.0
    By Jon Cohen in forum authorevents.vaughn
    Replies: 1
    Last Post: 05-31-2000, 12:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center