Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to write to macro to only delete rows under certain conditions

Hi there,

I need to delete rows of data which the last column in the range is either a
blank or a non-integer. If the last column contains a integer, it does not
delete that particular row

How do I do that?

example given below:

A1 1.3233
A2
A3 6
A4 0.823
A5
A6 9
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default how to write to macro to only delete rows under certain conditions

cazaril,

Assuming that your have a block of data that starts in A1 (all the columns are adjacent, with no
fully blank columns or rows interrupting the table), this macro should do what you want.

HTH,
Bernie
MS Excel MVP

Sub DeleteRows()
Dim myRows As Long
Dim myCol As Integer
Range("A1").EntireColumn.Insert
myRows = Range("B65536").End(xlUp).Row
myCol = Range("B65536").End(xlUp).CurrentRegion.Columns.Co unt

Range("A1").Value = "Delete Row criteria"
Range("A2:A" & myRows).FormulaR1C1 = _
"=IF(OR(RC[" & myCol & "]<INT(RC[" & myCol & _
"]),RC[" & myCol & "]=""""),""SortLow"",""SortHigh"")"
With Range("A:A")
.Copy
.PasteSpecial Paste:=xlValues
End With
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
Columns("A:A").Find(What:="SortLow", After:=Range("A1")).Select
Range(Selection, Selection.End(xlDown)).EntireRow.Delete
Range("A1").EntireColumn.Delete
End Sub



"cazaril" wrote in message
...
Hi there,

I need to delete rows of data which the last column in the range is either a
blank or a non-integer. If the last column contains a integer, it does not
delete that particular row

How do I do that?

example given below:

A1 1.3233
A2
A3 6
A4 0.823
A5
A6 9



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default how to write to macro to only delete rows under certain conditions

I am going to assume that you have the data you are interested in selected.
You could easily define a range to use instead of the selection range I am
using.

Sub delRows()
Dim currRow As Long

For currRow = Selection.Row + Selection.Rows.Count - 1 To Selection.Row Step
-1
If (IsEmpty(Cells(currRow, Selection.Column + Selection.Columns.Count -
1)) Or _
Cells(currRow, Selection.Column + Selection.Columns.Count - 1) <
Int(Cells(currRow, Selection.Column + Selection.Columns.Count - 1))) Then
Rows(currRow).Delete Shift:=xlUp
End If
Next
End Sub


"cazaril" wrote:

Hi there,

I need to delete rows of data which the last column in the range is either a
blank or a non-integer. If the last column contains a integer, it does not
delete that particular row

How do I do that?

example given below:

A1 1.3233
A2
A3 6
A4 0.823
A5
A6 9

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
how do i write a macro that will add rows into a spreadsheet BROCK8292 Excel Discussion (Misc queries) 5 April 30th 07 08:32 PM
Delete rows from a protected sheet (write macro) Matt Excel Programming 2 December 3rd 05 01:28 AM
How do I write a macro to delete all rows from the first empty ro. Jon M[_3_] Excel Programming 2 May 12th 05 06:01 PM
How do I write a macro in XL that will delete 1st row and save th. Nitin Excel Programming 1 March 16th 05 04:04 PM
How to write a VBA code to select certain rows based on certain conditions [email protected] Excel Programming 4 June 24th 04 09:25 PM


All times are GMT +1. The time now is 03:24 PM.

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"