ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Code for deleting rows with specific value (https://www.excelbanter.com/excel-programming/381185-vba-code-deleting-rows-specific-value.html)

Robert[_30_]

VBA Code for deleting rows with specific value
 
Hi,

Can some one assist me with the following:
I want to create a macro that deletes all lines that contain a certain
value in column A.

For example
A
1 EE
2 EE
3 EE
4 EE
5 DD
6 DD
7 DD
8 DD
9 DD
10 DD

Does anyone knows which code to use for deleting all lines with "EE" om
column A?

All suggestions are mostly appreciated!

Thanks a lot

Regards,
Robert


[email protected]

VBA Code for deleting rows with specific value
 

Hi Robert,

Try this... assume the data is in sheet1 (change as you like),

amend this row if you want to delete different columns ("A") and data
="EE").

If Cells(R, "A").Value = "EE)" Then .Rows(R).Delete

Sub DeleteRowEE()

Application.ScreenUpdating = False

Sheets("Sheet1").Select
Range("a1").Select

Dim R As Long
With Worksheets("Sheet1")
For R = .UsedRange.Rows.Count To 1 Step -1
If Cells(R, "A").Value = "EE)" Then .Rows(R).Delete
Next

End With
Application.ScreenUpdating = True

End Sub

Hopr it helps

P

Robert wrote:
Hi,

Can some one assist me with the following:
I want to create a macro that deletes all lines that contain a certain
value in column A.

For example
A
1 EE
2 EE
3 EE
4 EE
5 DD
6 DD
7 DD
8 DD
9 DD
10 DD

Does anyone knows which code to use for deleting all lines with "EE" om
column A?

All suggestions are mostly appreciated!

Thanks a lot

Regards,
Robert



Robert[_30_]

VBA Code for deleting rows with specific value
 
Can you also tell me how to refer to refer to another sheet (in which
the rows are located)? say for example "Sheet2" contains the data and
the command buttow will be put in "Sheet1"

Thanks again

Robert



Tom Ogilvy schreef:
Sub DeleteRows()
Dim rng as Range
set rng = columns(1).Find("EE")
if not rng is nothing then
do
rng.EntireRow.Delete
set rng = columns(1).Find("EE")
Loop while not rng is nothing
End if
End Sub

--
Regards,
Tom Ogilvy


"Robert" wrote:

Hi,

Can some one assist me with the following:
I want to create a macro that deletes all lines that contain a certain
value in column A.

For example
A
1 EE
2 EE
3 EE
4 EE
5 DD
6 DD
7 DD
8 DD
9 DD
10 DD

Does anyone knows which code to use for deleting all lines with "EE" om
column A?

All suggestions are mostly appreciated!

Thanks a lot

Regards,
Robert





All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com