Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Delete a Row if a Certain Value is in Column C

I am looking for some code that will delete an entire row in Sheet "Sales
Mix" if Column C contains certain values. These values are held within a
Range Name "Products_Not_Required". This range covers A:B and the values are
in Column A.

At the moment I have the following code which I can only get to work by
specifying one value within the code itself, that value is 7 i.e. if value
37 is in Column C anywhere then the entire row is deleted and all Rows shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
..Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete a Row if a Certain Value is in Column C

Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message ...
I am looking for some code that will delete an entire row in Sheet "Sales
Mix" if Column C contains certain values. These values are held within a
Range Name "Products_Not_Required". This range covers A:B and the values are
in Column A.

At the moment I have the following code which I can only get to work by
specifying one value within the code itself, that value is 7 i.e. if value
37 is in Column C anywhere then the entire row is deleted and all Rows shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Delete a Row if a Certain Value is in Column C

Hi Ron, that example I had was actually your code. Would prefer to use a
Range name as then I don't have to worry about changing the VB code as other
users will be updating the "Products_Not_required"


"Ron de Bruin" wrote in message
...
Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
I am looking for some code that will delete an entire row in Sheet

"Sales
Mix" if Column C contains certain values. These values are held within a
Range Name "Products_Not_Required". This range covers A:B and the values

are
in Column A.

At the moment I have the following code which I can only get to work by
specifying one value within the code itself, that value is 7 i.e. if

value
37 is in Column C anywhere then the entire row is deleted and all Rows

shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete a Row if a Certain Value is in Column C

Hi

In which row your data start?
The "Products_Not_required' range must be above that line.



--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message ...
Hi Ron, that example I had was actually your code. Would prefer to use a
Range name as then I don't have to worry about changing the VB code as other
users will be updating the "Products_Not_required"


"Ron de Bruin" wrote in message
...
Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
I am looking for some code that will delete an entire row in Sheet

"Sales
Mix" if Column C contains certain values. These values are held within a
Range Name "Products_Not_Required". This range covers A:B and the values

are
in Column A.

At the moment I have the following code which I can only get to work by
specifying one value within the code itself, that value is 7 i.e. if

value
37 is in Column C anywhere then the entire row is deleted and all Rows

shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Delete a Row if a Certain Value is in Column C

Ron

My data i.e. the rows of data I may want to delete starts in C2 on Sheet
Sales Mix, the "Products_Not_Required" named range is on Sheet Mster
starting at A468. IS it not possible to specify a named range within a
Macro?

Thanks


"Ron de Bruin" wrote in message
...
Hi

In which row your data start?
The "Products_Not_required' range must be above that line.



--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
Hi Ron, that example I had was actually your code. Would prefer to use a
Range name as then I don't have to worry about changing the VB code as

other
users will be updating the "Products_Not_required"


"Ron de Bruin" wrote in message
...
Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
I am looking for some code that will delete an entire row in Sheet

"Sales
Mix" if Column C contains certain values. These values are held

within a
Range Name "Products_Not_Required". This range covers A:B and the

values
are
in Column A.

At the moment I have the following code which I can only get to work

by
specifying one value within the code itself, that value is 7 i.e. if

value
37 is in Column C anywhere then the entire row is deleted and all

Rows
shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete a Row if a Certain Value is in Column C

range("Products_Not_Required")

would be how you refer to a named range.

msgbox range("Products_Not_Required").Address(External:=T rue)

or

for each cell in range("Products_Not_Required")

as examples.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Ron

My data i.e. the rows of data I may want to delete starts in C2 on Sheet
Sales Mix, the "Products_Not_Required" named range is on Sheet Mster
starting at A468. IS it not possible to specify a named range within a
Macro?

Thanks


"Ron de Bruin" wrote in message
...
Hi

In which row your data start?
The "Products_Not_required' range must be above that line.



--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
Hi Ron, that example I had was actually your code. Would prefer to use

a
Range name as then I don't have to worry about changing the VB code as

other
users will be updating the "Products_Not_required"


"Ron de Bruin" wrote in message
...
Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message
...
I am looking for some code that will delete an entire row in Sheet
"Sales
Mix" if Column C contains certain values. These values are held

within a
Range Name "Products_Not_Required". This range covers A:B and the

values
are
in Column A.

At the moment I have the following code which I can only get to

work
by
specifying one value within the code itself, that value is 7 i.e.

if
value
37 is in Column C anywhere then the entire row is deleted and all

Rows
shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub












  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete a Row if a Certain Value is in Column C

Hi John

Sorry for the late response

Maybe this is a faster solution for you.
I use AdvancedFilter in this example

Try it in a test workbook

The Sheet with the criteria is named "CriteriaSheet" in this example
A1 must have the same header as C1 in the activesheet with data.
In A2 :A? you fill in the values you want to delete.

C1:C? is the data range on the Activesheet
A1:A? is the criteria on the sheet "CriteriaSheet"

Note: A1 and C1 must have the same header


Sub Filtertest()
Dim rng As Range
Dim CriteriaRng As Range

With ActiveSheet
'Set the AdvancedFilter range
'C1 is the header cell
Set rng = .Range("C1:C" & .Range("C" & Rows.Count).End(xlUp).Row)

With Sheets("CriteriaSheet")
'Set the CriteriaRange range
'A1 must have the same cell.value(Header) as in C1 in the ActiveSheet
Set CriteriaRng = .Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row)
End With

'Filter the range
rng.AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=CriteriaRng, Unique:=False

'Set the delete range
On Error Resume Next
Set rng = rng.Offset(1, 0).Resize(Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)

'Delete visible cells
rng.EntireRow.Delete

'Show all the data
.ShowAllData
On Error GoTo 0

Application.Goto .Range("A1"), True
End With

End Sub





--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message ...
Ron

My data i.e. the rows of data I may want to delete starts in C2 on Sheet
Sales Mix, the "Products_Not_Required" named range is on Sheet Mster
starting at A468. IS it not possible to specify a named range within a
Macro?

Thanks


"Ron de Bruin" wrote in message
...
Hi

In which row your data start?
The "Products_Not_required' range must be above that line.



--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message

...
Hi Ron, that example I had was actually your code. Would prefer to use a
Range name as then I don't have to worry about changing the VB code as

other
users will be updating the "Products_Not_required"


"Ron de Bruin" wrote in message
...
Hi John

I have a example that use a Inputbox
Maybe you like that.
http://www.rondebruin.nl/delete.htm
(See the Find examples)

Post back if you really want to use the data in Column A
I will make a example for you then

--
Regards Ron de Bruin
http://www.rondebruin.nl


"John" wrote in message
...
I am looking for some code that will delete an entire row in Sheet
"Sales
Mix" if Column C contains certain values. These values are held

within a
Range Name "Products_Not_Required". This range covers A:B and the

values
are
in Column A.

At the moment I have the following code which I can only get to work

by
specifying one value within the code itself, that value is 7 i.e. if
value
37 is in Column C anywhere then the entire row is deleted and all

Rows
shift
up one.

Thanks

Public Sub SelectiveDelete()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long


Sheets("Sales Mix").Select
With ActiveSheet
.DisplayPageBreaks = False

StartRow = 2
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "C").Value) Then

ElseIf .Cells(Lrow, "c").Value = "37" Then
.Rows(Lrow).EntireRow.Delete Shift:=xlUp

End If
Next
End With


With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub












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
Cannot delete a column Art Excel Discussion (Misc queries) 0 December 10th 09 10:47 PM
Copy column header to next column, delete & delete every nth colum genehunter New Users to Excel 1 June 2nd 09 03:57 PM
delete cells column. Delete empty cells myshak Excel Worksheet Functions 0 March 9th 09 10:59 PM
How do I delete everything after a / in a column? henderson Excel Worksheet Functions 17 July 19th 07 06:55 PM
Delete row if value in Column X is 0? CapitolMike Excel Programming 1 January 22nd 04 03:27 PM


All times are GMT +1. The time now is 12:32 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"