Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default If Then HELP!!!

Dim r As Range
For Each r In ActiveSheet.UsedRange
If r.Interior.ColorIndex = 6 Then Cell.ange(Selection, Selection(30 -
Selection.Value)).EntireRow.Insert
Next

I'm not getting this right, and am unsure where to make a fix.
I want this code to select every cell that is yellow Insert rows based on
the value in the cell up to 30. So if there is a 16 it will insert 14 rows,
15 inserts 15 rows etc etc..... So what am I doing wrong with this code??

THANKS!!!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default If Then HELP!!!

You have two problems. One, you have a typo at "Then Cell.ange". Secondly,
your "UsedRange" continually changes when you insert cells. When I tried
your code, it looped forever. You will need to find a way to make the code
loop through the used cells but eventually come to the end.

For example, try a Do...While loop and have the end condition include an
entirely blank or unfilled cell.

Good luck,
Pflugs

"bodhisatvaofboogie" wrote:

Dim r As Range
For Each r In ActiveSheet.UsedRange
If r.Interior.ColorIndex = 6 Then Cell.ange(Selection, Selection(30 -
Selection.Value)).EntireRow.Insert
Next

I'm not getting this right, and am unsure where to make a fix.
I want this code to select every cell that is yellow Insert rows based on
the value in the cell up to 30. So if there is a 16 it will insert 14 rows,
15 inserts 15 rows etc etc..... So what am I doing wrong with this code??

THANKS!!!!!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default If Then HELP!!!

Yeah I caught that typo and tried it again....it does nothing for me...didn't
even loop like you said. So what would you suggest the Code look like, I'm
obiously too novice to figure it out.. :) THANKS!!!

"Pflugs" wrote:

You have two problems. One, you have a typo at "Then Cell.ange". Secondly,
your "UsedRange" continually changes when you insert cells. When I tried
your code, it looped forever. You will need to find a way to make the code
loop through the used cells but eventually come to the end.

For example, try a Do...While loop and have the end condition include an
entirely blank or unfilled cell.

Good luck,
Pflugs

"bodhisatvaofboogie" wrote:

Dim r As Range
For Each r In ActiveSheet.UsedRange
If r.Interior.ColorIndex = 6 Then Cell.ange(Selection, Selection(30 -
Selection.Value)).EntireRow.Insert
Next

I'm not getting this right, and am unsure where to make a fix.
I want this code to select every cell that is yellow Insert rows based on
the value in the cell up to 30. So if there is a 16 it will insert 14 rows,
15 inserts 15 rows etc etc..... So what am I doing wrong with this code??

THANKS!!!!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default If Then HELP!!!

hi,
using UsedRange will keep you going forever for as you as rows, you add range.
ange???? i think this is suppose to be Range.
selection??? your not selecting anything.
try this
Sub MacAddRows()
Dim r As Range
Dim r1 As Range
Dim lr As Range

Set r = Range("A1")
Set lr = Range("a65000").End(xlUp)
'MsgBox lr.Address ' for debug perposes only
Do While r.Address < lr.Address
Set r1 = r.Offset(1, 0)
If r.Interior.ColorIndex = 6 Then
Range(r1, r1(30 - r.Value)).EntireRow.Insert
Set r1 = r.Offset(1, 0)
Range(r1, r1(30 - r.Value)).Interior.ColorIndex = 0
End If
Set r = r1
'MsgBox r.Address 'for debug purposes only
Loop

End Sub
regards
FSt1

"bodhisatvaofboogie" wrote:

Dim r As Range
For Each r In ActiveSheet.UsedRange
If r.Interior.ColorIndex = 6 Then Cell.ange(Selection, Selection(30 -
Selection.Value)).EntireRow.Insert
Next

I'm not getting this right, and am unsure where to make a fix.
I want this code to select every cell that is yellow Insert rows based on
the value in the cell up to 30. So if there is a 16 it will insert 14 rows,
15 inserts 15 rows etc etc..... So what am I doing wrong with this code??

THANKS!!!!!

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



All times are GMT +1. The time now is 06:41 AM.

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

About Us

"It's about Microsoft Excel"