Stepping Through Rows

D

DavidW

I am attempting to have a macro copy and then remove certain rows from
worksheet "Master" to worksheet "Complete". The following code snippet
gets the values for the last row and column for each worksheet:


Code:
--------------------
LcMaster = LastColumn(Sheets("Master")) 'last column of Master
LrMaster = LastRow(Sheets("Master")) ' last row of Master
LastCell = Cells(LrMaster, LcMaster).Address ' last cell of Master
Lr = LastRow(Sheets("Complete")) + 1 ' row after the last row of Complete
--------------------


With that information, I need to step through each row in the "Master"
worksheet that has data. I need to check column H for data (a
completion date). If it has data it is moved. The code below works,
except that I would like for it to start on the second row instead of
the first:


Code:
--------------------
For Each rw In Worksheets("Master").Rows
If Len(Cells(rw.Row, "H")) > 0 Then
Set sourceRange = ActiveCell.EntireRow
Set destrange = Sheets("Complete").Rows(Lr + 1)
sourceRange.Copy destrange
sourceRange.EntireRow.Delete
End If
Next rw
--------------------


How can I get the For/Next loop to start at row 2?

Thanks.
 
P

PCLIVE

Try using a macro.

The first line finds the last cell with data in column A. This is assumed
to be the column that will include the first of six selected numbers by a
punter. The numbers should be entered across. This code assumes that the
lottery drawn numbers are entered across the top of the spreadsheet starting
at A1 and working over through F1. This code assumes that your punters'
numbers start at row 7. You can adjust as necessary. If a punter's number
matches any of the numbers entered across the top, then this code colors
that cell Green. You can adjust the color. Hope you find this useful.

Sub test()
lr = Range("A65536").End(xlUp).Row

For i = 1 To 6
For Each cell In Range("A7:F" & lr)
'If n = 7 Then End
If cell.Value = Cells(1, i).Value _
Then
With cell.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
Else:
End If
Next cell
Next i

End Sub
 
P

PCLIVE

Sorry. Posted to wrong thread.


PCLIVE said:
Try using a macro.

The first line finds the last cell with data in column A. This is assumed
to be the column that will include the first of six selected numbers by a
punter. The numbers should be entered across. This code assumes that the
lottery drawn numbers are entered across the top of the spreadsheet
starting at A1 and working over through F1. This code assumes that your
punters' numbers start at row 7. You can adjust as necessary. If a
punter's number matches any of the numbers entered across the top, then
this code colors that cell Green. You can adjust the color. Hope you
find this useful.

Sub test()
lr = Range("A65536").End(xlUp).Row

For i = 1 To 6
For Each cell In Range("A7:F" & lr)
'If n = 7 Then End
If cell.Value = Cells(1, i).Value _
Then
With cell.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
Else:
End If
Next cell
Next i

End Sub
 

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

Similar Threads

Loop Macro 3
Using ActiveCell to specify a column 5
Loop 2
Copy to Next Blank Row 5
Last Cell on a Worksheet 2
Copy cell range to another sheet 3
Pasting problems 1
this code crashes excel. How come? 3

Top