Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete Cells when error
Hi,
what am I doing wrong here? I need to delete cells D & E if there is an error in D. With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For iCtr = LrowinD To FrowinD Step -1 With .Cells(LrowinD, "D") If IsError(.Value) Then .Cells(LrowinD, "D:E").Select Selection.Delete Shift:=xlUp End If End With Next End With Thanks for yor help. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete Cells when error
Karen,
Try, Sub marine() FrowinD = 1 With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For ictr = LrowinD To FrowinD Step -1 If IsError(Cells(ictr, 4).Value) Then Range("D" & ictr & ":E" & ictr).Select Selection.Delete Shift:=xlUp End If Next End With End Sub Mike "Karen53" wrote: Hi, what am I doing wrong here? I need to delete cells D & E if there is an error in D. With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For iCtr = LrowinD To FrowinD Step -1 With .Cells(LrowinD, "D") If IsError(.Value) Then .Cells(LrowinD, "D:E").Select Selection.Delete Shift:=xlUp End If End With Next End With Thanks for yor help. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete Cells when error
Yea!!! Thank you Mike!
"Mike H" wrote: Karen, Try, Sub marine() FrowinD = 1 With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For ictr = LrowinD To FrowinD Step -1 If IsError(Cells(ictr, 4).Value) Then Range("D" & ictr & ":E" & ictr).Select Selection.Delete Shift:=xlUp End If Next End With End Sub Mike "Karen53" wrote: Hi, what am I doing wrong here? I need to delete cells D & E if there is an error in D. With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For iCtr = LrowinD To FrowinD Step -1 With .Cells(LrowinD, "D") If IsError(.Value) Then .Cells(LrowinD, "D:E").Select Selection.Delete Shift:=xlUp End If End With Next End With Thanks for yor help. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete Cells when error
Mike has provided a nice solution. However, I would recommend
removing the select line. It is good coding practice to not select anything if not absolutely necessary. You could replace this: If IsError(Cells(ictr, 4).Value) Then Range("D" & ictr & ":E" & ictr).Select Selection.Delete Shift:=xlUp End If With this: If IsError(Cells(ictr, 4).Value) Then _ Range("D" & ictr & ":E" & ictr).Delete Shift:=xlUp Karen53 wrote: Yea!!! Thank you Mike! "Mike H" wrote: Karen, Try, Sub marine() FrowinD = 1 With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For ictr = LrowinD To FrowinD Step -1 If IsError(Cells(ictr, 4).Value) Then Range("D" & ictr & ":E" & ictr).Select Selection.Delete Shift:=xlUp End If Next End With End Sub Mike "Karen53" wrote: Hi, what am I doing wrong here? I need to delete cells D & E if there is an error in D. With Sheets("Table") LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row For iCtr = LrowinD To FrowinD Step -1 With .Cells(LrowinD, "D") If IsError(.Value) Then .Cells(LrowinD, "D:E").Select Selection.Delete Shift:=xlUp End If End With Next End With Thanks for yor help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
delete cells column. Delete empty cells | Excel Worksheet Functions | |||
delete error/blank cells | Excel Worksheet Functions | |||
How to delete all the blanc cells in a worksheet and shift cells l | Excel Discussion (Misc queries) | |||
macro to select cells containing specific text and delete all cells but these | Excel Programming | |||
Delete specific cells contents in a row with some locked cells in the same row | Excel Programming |