Macro/ VbA Forumla Help-Deleteing Entire Rows
Closed
dumow880
Posts
7
Registration date
Thursday July 7, 2011
Status
Member
Last seen
July 17, 2012
-
Jul 8, 2011 at 03:13 PM
dumow880 Posts 7 Registration date Thursday July 7, 2011 Status Member Last seen July 17, 2012 - Jul 19, 2011 at 09:14 AM
dumow880 Posts 7 Registration date Thursday July 7, 2011 Status Member Last seen July 17, 2012 - Jul 19, 2011 at 09:14 AM
Related:
- Macro/ VbA Forumla Help-Deleteing Entire Rows
- Vba case like - Guide
- Number to words in excel formula without vba - Guide
- Vba check if value is in array - Guide
- Vba color index - Guide
- How to open vba in excel - Guide
6 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jul 9, 2011 at 06:49 AM
Jul 9, 2011 at 06:49 AM
Sub test() Dim j As Integer For j = Range("F1").End(xlDown).Row To 2 Step -1 If Cells(j, "F") + Cells(j - 1, "F") = 0 Then Range(Cells(j, "F"), Cells(j - 1, "F")).EntireRow.Delete End If Next j End Sub
DO THIS EXPERIMENT IN A SAMPLE DATA FIRST.WHEN YOU DO IT IN ORIGINAL FILE DO IT ON A COPY OF THE ORIGINAL FILE AND NOT ORIGINAL FILE.
dumow880
Posts
7
Registration date
Thursday July 7, 2011
Status
Member
Last seen
July 17, 2012
1
Jul 12, 2011 at 09:36 AM
Jul 12, 2011 at 09:36 AM
Thanks a ton, it works and I really appreciate it. Big time saver.
However, I do have one more question in regards to the formula:
After it runs and completes the task it retruns the error message: "Run-time error '13' Type Mismatch". I click Debug and it pulls up the Microsoft Visual Basic Module. Highlighted is the fourth line of programming, "If Cells(j, "F") + Cells(j - 1, "F") = 0 Then", with a yellow arrow facing it and the row highlighted yellow.
What is this error message saying?
However, I do have one more question in regards to the formula:
After it runs and completes the task it retruns the error message: "Run-time error '13' Type Mismatch". I click Debug and it pulls up the Microsoft Visual Basic Module. Highlighted is the fourth line of programming, "If Cells(j, "F") + Cells(j - 1, "F") = 0 Then", with a yellow arrow facing it and the row highlighted yellow.
What is this error message saying?
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jul 12, 2011 at 09:36 PM
Jul 12, 2011 at 09:36 PM
I think you are having a header row in row no;. 1
in which case replace this statement in the macro
For j = Range("F1").End(xlDown).Row To 2 Step -1
by
For j = Range("F1").End(xlDown).Row To 3 Step -1
in which case replace this statement in the macro
For j = Range("F1").End(xlDown).Row To 2 Step -1
by
For j = Range("F1").End(xlDown).Row To 3 Step -1
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jul 13, 2011 at 11:54 PM
Jul 13, 2011 at 11:54 PM
use the statement
this will work even if the re are gaps in c;column H
one more thing do not select unnecessarily
for example use something like this
range(range("H2"),cells(rows.count,"H").end(xlup)).select
this will work even if the re are gaps in c;column H
one more thing do not select unnecessarily
for example use something like this
dim r as range set r=range(range("H2"),cells(rows.count,"H").end(xlup)) r.copy etc etc.
Didn't find the answer you are looking for?
Ask a question
dumow880
Posts
7
Registration date
Thursday July 7, 2011
Status
Member
Last seen
July 17, 2012
1
Jul 13, 2011 at 12:37 PM
Jul 13, 2011 at 12:37 PM
Works great; thanks a lot.
One last question, but on macro I currently have.
Listed below is the Macro. Currently it has a set "range" to autofill ("H2:H8000"). What is the appropriate programming string to have it just fill to the end of the data in Column H, instead of having a defined H2:H8000?
Thanks
------------
Sub ThirdStep()
Range("H2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[1]C[-1],""dup"",0)"
Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H8000")
Range("H2:H8000").Select
Columns("H:H").Select
Selection.Copy
Columns("H:H").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 8.29
Range("G7").Select
End Sub
One last question, but on macro I currently have.
Listed below is the Macro. Currently it has a set "range" to autofill ("H2:H8000"). What is the appropriate programming string to have it just fill to the end of the data in Column H, instead of having a defined H2:H8000?
Thanks
------------
Sub ThirdStep()
Range("H2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[1]C[-1],""dup"",0)"
Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H8000")
Range("H2:H8000").Select
Columns("H:H").Select
Selection.Copy
Columns("H:H").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 8.29
Range("G7").Select
End Sub
dumow880
Posts
7
Registration date
Thursday July 7, 2011
Status
Member
Last seen
July 17, 2012
1
Jul 19, 2011 at 09:14 AM
Jul 19, 2011 at 09:14 AM
Thanks Venkat1926.
So if I'm following correctly, the final macro would read:
Sub Scan_column()
dim r as range
set r=range(range("H2"),cells(rows.count,"H").end(xlup))
r.copy
End Sub
So if I'm following correctly, the final macro would read:
Sub Scan_column()
dim r as range
set r=range(range("H2"),cells(rows.count,"H").end(xlup))
r.copy
End Sub