dellehurley
Board Regular
- Joined
- Sep 26, 2009
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
I have a loop issue.
I have a worksheet which I am preparing to be added to a database.
I need to delete the rows where Column A matches Column C.
Column D is just there while I am working on this.
NB. I have 3 floating buttons so I would prefer if I could delete the row from column A to D only.
The first code works highlighting the files to be deleted but I cannot get it to work when I change the instruction to delete.
This works
This doesn't work
Thanks for your help.
I have a worksheet which I am preparing to be added to a database.
I need to delete the rows where Column A matches Column C.
Column D is just there while I am working on this.
NB. I have 3 floating buttons so I would prefer if I could delete the row from column A to D only.
The first code works highlighting the files to be deleted but I cannot get it to work when I change the instruction to delete.
This works
VBA Code:
Sub Matches()
Dim lastRow, i As Long
lastRow = ThisWorkbook.Sheets("ImportRINS").Cells(Rows.Count, "A").End(xlUp).Row
'On Error Resume Next
For i = 2 To lastRow
If Cells(i, 1).Value = Cells(i, 3).Value Then
Rows(i).Interior.ColorIndex = 4
End If
Next i
End Sub
VBA Code:
Sub Matches()
Dim lastRow, i As Long
lastRow = ThisWorkbook.Sheets("ImportRINS").Cells(Rows.Count, "A").End(xlUp).Row
'On Error Resume Next
For i = 2 To lastRow
If Cells(i, 1).Value = Cells(i, 3).Value Then
Range(i, 4).Delete Shift:=xlToUpt 'I also tried Rows(i).EntireRow.Delete Range.Cells(i).EntireRow.Delete with and without i=i-1 after this row
End If
Next i
End Sub
Data_Entry_Form_ver_25d.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
2 | David (b. 1950) | 16895 | FALSE | |||
3 | Elizabeth (b. 1965) | 16902 | FALSE | |||
4 | Braga, Jose Maria (b. 1897) | 16898 | Braga, Jose Maria (b. 1897) | TRUE | ||
5 | Cairnduff, Cyril Wilberforce (b. 1898) | 16890 | Cairnduff, Cyril Wilberforce (b. 1898) | TRUE | ||
6 | Cairnduff, Gwendoline May (b. 1920) | 16887 | Cairnduff, Gwendoline May (b. 1920) | TRUE | ||
7 | Coates, Doris Maude (b. 1900) | 16909 | Coates, Doris Maude (b. 1899) | FALSE | ||
8 | da Luz, Augusta da Conceição Ozorio (b. 1898) | 16899 | da Luz, Augusta Isabel da Conceição Ozorio (b. 1898) | FALSE | ||
9 | Donnelly, Matthew (b. 1884) | 16888 | FALSE | |||
ImportRINS |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2:D9 | D2 | =A2=C2 |
Thanks for your help.