Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Macro to delete specific rows

I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Macro to delete specific rows

Hi
try the following

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Macro to delete specific rows

First, let me apologize for my blatant ignorance. i tried
copying and pasting it into module 4 after another macro i
have in. Now i can't figure out how to either assign your
macro to a button, or simply run it. when i go to the
macro menu, it is not listed.

thanks again for your time.
steve
-----Original Message-----
Hi
try the following

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance,

if
cell b3 has the letters WX in it. I want to delete all

of
row b.

I appreciate all your time and effort.
Steve

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Macro to delete specific rows

Hi
should work if you pasted this macro in a module of your current
workbook (it should appear in the macro menu)
You may have a look at the following site for more information how to
use/install macros

http://www.mvps.org/dmcritchie/excel/getstarted.htm


--
Regards
Frank Kabel
Frankfurt, Germany

wrote:
First, let me apologize for my blatant ignorance. i tried
copying and pasting it into module 4 after another macro i
have in. Now i can't figure out how to either assign your
macro to a button, or simply run it. when i go to the
macro menu, it is not listed.

thanks again for your time.
steve
-----Original Message-----
Hi
try the following

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve

.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Macro to delete specific rows

All right, i finally got it too work. i have one final
question....How do I add multiple values. so that along w/
wx, it will also look for pax, cus, atc.

once again I thank you all for your help.
Steve
-----Original Message-----
Hi
should work if you pasted this macro in a module of your

current
workbook (it should appear in the macro menu)
You may have a look at the following site for more

information how to
use/install macros

http://www.mvps.org/dmcritchie/excel/getstarted.htm


--
Regards
Frank Kabel
Frankfurt, Germany

wrote:
First, let me apologize for my blatant ignorance. i

tried
copying and pasting it into module 4 after another

macro i
have in. Now i can't figure out how to either assign

your
macro to a button, or simply run it. when i go to the
macro menu, it is not listed.

thanks again for your time.
steve
-----Original Message-----
Hi
try the following

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I am looking for a macro to delete an entire row,

when
there is a specific occurance in a cell. For

instance, if
cell b3 has the letters WX in it. I want to delete

all of
row b.

I appreciate all your time and effort.
Steve
.


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Macro to delete specific rows

Hi Steve
so you want to delete the row if either of these values is in column B.
Try

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" or _
cells(r,"B").value = "PAX" or _
cells(r,"B").value = "CUS" or _
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R


--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
All right, i finally got it too work. i have one final
question....How do I add multiple values. so that along w/
wx, it will also look for pax, cus, atc.

once again I thank you all for your help.
Steve
-----Original Message-----
Hi
should work if you pasted this macro in a module of your current
workbook (it should appear in the macro menu)
You may have a look at the following site for more information how

to
use/install macros

http://www.mvps.org/dmcritchie/excel/getstarted.htm


--
Regards
Frank Kabel
Frankfurt, Germany

wrote:
First, let me apologize for my blatant ignorance. i tried
copying and pasting it into module 4 after another macro i
have in. Now i can't figure out how to either assign your
macro to a button, or simply run it. when i go to the
macro menu, it is not listed.

thanks again for your time.
steve
-----Original Message-----
Hi
try the following

Public Sub DeleteRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If cells(r,"B").value = "WX" Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve
.


.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to delete specific rows

Steve,
Try something like

Dim RowNdx As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "B").Value = "WX" Then
Rows(RowNdx).Delete
End If
Next RowNdx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Steve" wrote in message
...
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Macro to delete specific rows

Do you mean you want to delete row 3 or column B?

Try something like:

Sub deleteRow()

If InStr(Range("B3"), "WX") Then
Rows(3).Delete
End If

End Sub

"Steve" wrote in message
...
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance, if
cell b3 has the letters WX in it. I want to delete all of
row b.

I appreciate all your time and effort.
Steve



  #9   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Macro to delete specific rows

HEY...MY BAD.... I MEANT I WANT TO DELETE ROW 3.
-----Original Message-----
Do you mean you want to delete row 3 or column B?

Try something like:

Sub deleteRow()

If InStr(Range("B3"), "WX") Then
Rows(3).Delete
End If

End Sub

"Steve" wrote in

message
...
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance,

if
cell b3 has the letters WX in it. I want to delete all

of
row b.

I appreciate all your time and effort.
Steve



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Macro to delete specific rows

the problem i am having is the spreadsheet will have
several occurances, not in any order. how do i set a range
to delete any row with that occurance?
i appreciate your patience. I am still learning macros and
VBA.
Thanks,
Steve
-----Original Message-----
Do you mean you want to delete row 3 or column B?

Try something like:

Sub deleteRow()

If InStr(Range("B3"), "WX") Then
Rows(3).Delete
End If

End Sub

"Steve" wrote in

message
...
I am looking for a macro to delete an entire row, when
there is a specific occurance in a cell. For instance,

if
cell b3 has the letters WX in it. I want to delete all

of
row b.

I appreciate all your time and effort.
Steve



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows with specific text David New Users to Excel 5 April 3rd 23 07:29 PM
Delete specific rows of data Roger Bell New Users to Excel 3 June 19th 07 08:40 AM
Macro to delete rows containing specific data Slohcin New Users to Excel 2 December 20th 06 11:52 AM
select and delete specific rows Paulg Excel Discussion (Misc queries) 1 August 22nd 06 04:12 PM
Delete rows if specific criteria not met. SITCFanTN Excel Worksheet Functions 3 July 5th 06 12:20 AM


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"