ExcelTip.com
Account Icon Account Icon Account Icon
ExcelTip.com

Go Back   Excel Help Forum > Usenet Groups > Excel Programming

Notices

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-04-2008, 09:26 PM
anmck anmck is offline
Registered User
 
Join Date: 04 Oct 2008
Location: montreal
Posts: 7
anmck is on a distinguished road
Red face Alternating color of lines

I need to write a macro in order to format a worksheet so that the line colors are alternating (ex: grey and white), for easy reading after print. However, the file will be change constantly by people that don't care much about formating colors....So I want to assing this macro to a button (I know how to do this part!)

I tried, but it didn't compile, and I couldn't get it right...

NOTE: The selection should start not from the begining (ex: line 4) and be applied until it meets an empty field in the A column.

Here is what it looked like.... I can do with a brand new code, but I would learn better if someone can also tell me what I did wrong!

To those who read the previous one:
Sorry about the code... I used the forum 2 years ago, but it wasn't like this.. (as far as I can remember!) Hope it satifies the rules now...It said not to reply... hope that starting a new thread isn't bad either! So here it is again!

Code:
Dim Count As Integer, End As Integer
Count = 4

Do
Rows("Count:Count").Select
Selection.Interior.ColorIndex = 15
Count = Count + 2
Loop Until IsEmpty("ACount")

End = 5
Do
Rows("End:End").Select
Selection.Interior.ColorIndex = xlNone
End = End + 2
Loop Until Count < End
Thanx A LOT!

Last edited by anmck; 10-04-2008 at 10:20 PM.
Reply With Quote
  #2  
Old 10-04-2008, 09:53 PM
mudraker's Avatar
mudraker mudraker is offline
Forum Moderator
 
Join Date: 10 Nov 2003
Location: Melbourne, Australia
Posts: 3,052
mudraker will become famous soon enough mudraker will become famous soon enough
Conditional formating can do what you want
have a lok at
http://www.techonthenet.com/excel/qu...nd_format2.php

The resaon your macro did not compile is that certain words are reserved for Excel & or VBA and should nevewr be used as a variable name

Count is reserved - Whist you can use it as a variable name you should not
End is reserved and can never be used as avariable name - This variable name is what is causing your problem

This is the code I would to do it

Code:
Dim l4Row As Long
Dim lLR As Long

'find last used row
lLR = Cells(Rows.Count, "a").End(xlUp).Row

'clear rows colouring
Rows("4:" & lLR).Interior.ColorIndex = xlNone

'apply cell colouring
For l4Row = 4 To lLR Step 2
   Rows(l4Row).Interior.ColorIndex = 15
Next l4Row
__________________
Please Read Forum Rules Before Posting

Wrap VBA code by selecting the code and clicking the # icon or Read This

How To Cross Post politely

If my reply has assisted or failed to assist you I welcome your Feedback.
Reply With Quote
Reply

Bookmarks

New topics in Excel Programming


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternating color of lines anmck Excel Programming 1 10-04-2008 08:35 PM
copying and inserting huge amount of lines Guy Excel General 0 08-14-2008 03:32 PM
Multiple lines in single cell Bill Pearce Excel Miscellaneous 4 06-27-2008 09:40 AM
Pasting multiple lines of text into one cell hoopz Excel Miscellaneous 3 01-15-2008 04:39 PM
Extracting specific lines from datasheet SlipperyPete Excel Miscellaneous 5 12-21-2006 10:54 AM


All times are GMT -4. The time now is 05:49 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0