Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Change the row number in macro

Hi all,

I have to write a macro to fill grey to some rows depends on the weekday,
the following code works but sometimes there will be some new rows must be
inserted into the table, it is very time consuming to amend the code (row
number). Is that a possible way for improvement? Thanks

Sheets("Sheet1").Range("A10:J64").Select
Selection.Interior.ColorIndex = xlNone
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Change the row number in macro

What criteria causes the row to be colored grey? If it is empty? If it has
certain type data? If it does not have certain type data? I know you have
case set up but I can't see it.

At any rate, to set the max range for the used range you can find the last
used row in column A with:

lr= Cells(Rows.Count, 1).End(xlUp).Row

Then set your range with:

Sheets("Sheet1").Range("A10:J" & lr).Interior.ColorIndex = xlNone

That should clear all of the cells in the used range of any shading.

"jimmy" wrote:

Hi all,

I have to write a macro to fill grey to some rows depends on the weekday,
the following code works but sometimes there will be some new rows must be
inserted into the table, it is very time consuming to amend the code (row
number). Is that a possible way for improvement? Thanks

Sheets("Sheet1").Range("A10:J64").Select
Selection.Interior.ColorIndex = xlNone
.
.
.
Case 3 To 6
Sheets("Sheet1").Range("A10,10:12,16:16,30:52").Se lect
Selection.Interior.ColorIndex = 15
Case 7
Sheets("Sheet1").Range("A10,25:26,30:38,46:46,60:6 4").Select
Selection.Interior.ColorIndex = xlNone



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Change the row number in macro

Sorry for the misleading.
Color which row is depend on the weekday. For instance, if today is Monday,
fill "A3:D3", "A6:D6", "A11:D11", "A20:D20", Tuesday fill "A51:D51"...etc.
The problem is, if there are some new rows must be inserted, say four new
rows insert to row 2, 5, 9 and 15, then I need to amend all the code, i.e
Monday as "A4:D4", "A8:D8", "A14:D14", "A24:D24", Tuesday to
"A55:D55"...etc, very inconvenient. Any idea?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA write macro change column with 3 number digits to 4 digits the James C[_2_] Excel Discussion (Misc queries) 3 January 25th 10 03:12 PM
Macro to change row number within formula mpot4 Excel Programming 2 September 21st 05 03:55 AM
Macro to change a number to text Lori F Excel Programming 4 November 12th 03 04:44 PM
Macro to change a number to text Jake Marx[_3_] Excel Programming 1 November 11th 03 04:34 PM
Macro to change a number to text Lori F. Excel Programming 0 November 11th 03 04:28 PM


All times are GMT +1. The time now is 06:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"