|
|||||||||||||||||||||
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
Last edited by anmck; 10-04-2008 at 10:20 PM. |
|
#2
|
||||
|
||||
|
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.
|
![]() |
| Bookmarks |
New topics in Excel Programming
|
|
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |