Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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. -- DavidW ------------------------------------------------------------------------ DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630 View this thread: http://www.excelforum.com/showthread...hreadid=574343 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "DavidW" wrote in message ... 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. -- DavidW ------------------------------------------------------------------------ DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630 View this thread: http://www.excelforum.com/showthread...hreadid=574343 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry. Posted to wrong thread.
"PCLIVE" wrote in message ... 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 "DavidW" wrote in message ... 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. -- DavidW ------------------------------------------------------------------------ DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630 View this thread: http://www.excelforum.com/showthread...hreadid=574343 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Stepping in to a cell | Excel Discussion (Misc queries) | |||
Stepping Problem, | Excel Programming | |||
Stepping through For Each...Next backwards? | Excel Programming | |||
stepping down rows | Excel Programming | |||
Stepping through a column using FOR/NEXT | Excel Programming |