Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2003, 02:41 PM
Authorized User
 
Join Date: Aug 2003
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
Default Selecting a column

I have a excel sheet with 5 columns (A,B,C,D,E). I want to wite a macro to select column D and E and then change its font color. I have merged cells in Column A. What happens is that due to merged cells when i write the statement
         columns ("D:E").select or Range("$D:$E").select
it selects the whole sheet(from column A to column E). Could someone suggest a wayout to select column D and E only with merged cells in Column A.

Thanks

Ajitpal S Padda
__________________
Ajitpal S Padda
 
Old December 11th, 2003, 04:30 AM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Loop through all rows and check if the MergeCells property is set to True for the cell in column A. Here's an example (don't forget to set myStartRow and myEndRow):

For n = myStartRow to myEndRow
  If Cells(n,1).MergeCells = True Then 'Cell in column A is merged with another one
    Cells(n,1).Font.ColorIndex = 5 'Changes the font color to blue
  Else 'No merged cell
    Range(Cells(n,4),Cells(n,5)).Font.ColorIndex = 5 'Changes the font color to blue
  End If
Next

Note: this is not as fast as selecting columns, but it works...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting elements up until a certain one Frode XSLT 5 January 19th, 2006 01:22 PM
previous column & next column ct Excel VBA 4 August 19th, 2005 04:50 AM
template column and bound column hidayah ASP.NET 1.x and 2.0 Application Design 1 April 9th, 2005 03:50 PM
Selecting once where there are many onlyu2 MySQL 1 March 25th, 2004 06:22 AM
Compare two Items of data(in column A and column B ever Excel VBA 6 February 13th, 2004 02:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.