Solved

conditional row delete

Posted on 2013-10-23
4
152 Views
Last Modified: 2013-10-29
I have a worksheet with X number of columns (this can run up to 200 columns or more), but the exact number is variable. So, first have to calculate number of rows that happen to be in this particular worksheet.

Then, I want to go through each row and check the value initially in the the ninth column (I), then every 12 columns (U, AG...) thereafter to the end. The number of the last column having been determined in step 1 above. However, the end column will not be the last column checked. The last column will be about 4 columns after the last column checked. For example, because we are checking every 12 columns after column I, the last checked column ( I know this for certain ) will not be the last column in the worksheet, but will be about 4 columns before the end.

For a given row, if all values in all columns that were checked were below 2 and less than -2 (between 2 and -2), then delete the row.
0
Comment
Question by:vbaabv
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39595650
Can you provide a sample workbook?
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 39595669
Here is a macro that will check your data and delete rows if every twelfth value has an absolute value equal to or less than 2, starting with cell I2.
Sub Absolution()
Dim rg As Range
Dim i As Long, j As Long, nCols As Long
Dim bDelete As Boolean
Application.ScreenUpdating = False
Set rg = ActiveSheet.UsedRange
nCols = rg.Columns.Count
For i = rg.Rows.Count To 2 Step -1      'The first row is header labels. Don't check it for absolute values
    bDelete = True
    For j = 9 To nCols Step 12
        If IsNumeric(rg.Cells(i, j).Value) Then
            If Abs(rg.Cells(i, j).Value) > 2 Then
                bDelete = False
                Exit For
            End If
        End If
    Next
    If bDelete = True Then rg.Rows(i).EntireRow.Delete
Next
End Sub

Open in new window

AbsoluteValueDeleteQ28275433.xlsm
0
 

Author Comment

by:vbaabv
ID: 39609905
Thank you very much, byundt. Checking this script requires a somewhat complex set of data, so sorry for the delay in getting back to you. This is working very well. Thank you very much for your help.
0
 

Author Closing Comment

by:vbaabv
ID: 39609906
Thank you very much. Excellent work !
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now