Change the row number in macro

  • Thread starter Thread starter jimmy
  • Start date Start date
J

jimmy

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
 
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.
 
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top