View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Paige Paige is offline
external usenet poster
 
Posts: 270
Default Next and Loop Question

The following code attempts to fill in (or leave blank) what is in Columns H
and I based upon what is in Column A same row (i.e., whether Column A same
row is either filled in or blank) and what is on a certain cell in another
speadsheet (either 'Yes', 'No', or blank).

I need to modify it so that it doesn't run through all 1000 rows each time,
causing excessive run time; the code is cumbersome. Maybe by stopping at the
first blank cell in Column A (which I don't know how to do)? Can someone
advise how to fix this please?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
For Each c In Range("$H$14:$H$1000")
If c.Offset(0, -7).Value < "" And Worksheets("Input Tab
#1").Range("C16").Value
= "Yes" Then c.Value = c.Offset(-1, 0)
Next
For Each c In Range("$I$14:$I$1000")
If c.Offset(0, -8).Value < "" And Worksheets("Input Tab
#1").Range("C17").Value
= "Yes" Then c.Value = c.Offset(-1, 0)
Next

For Each c In Range("$H$14:$H$1000")
If c.Offset(0, -7).Value < "" And Worksheets("Input Tab
#1").Range("C16").Value
= "No" Then c.Value = c.Offset(-1, 0)
Next
For Each c In Range("$I$14:$I$1000")
If c.Offset(0, -8).Value < "" And Worksheets("Input Tab
#1").Range("C17").Value
= "No" Then c.Value = c.Offset(-1, 0)
Next

For Each c In Range("$H$14:$H$1000")
If c.Offset(0, -7).Value < "" And Worksheets("Input Tab
#1").Range("C16").Value
= "" Then c.Value = c.Offset(-1, 0)
Next
For Each c In Range("$I$14:$I$1000")
If c.Offset(0, -8).Value < "" And Worksheets("Input Tab
#1").Range("C17").Value
= "" Then c.Value = c.Offset(-1, 0)
Next

For Each c In Range("$H$14:$H$1000")
If c.Offset(0, -7).Value = "" Then c.Value = ""
Next
For Each c In Range("$I$14:$I$1000")
If c.Offset(0, -8).Value = "" Then c.Value = ""
Next

End Sub