ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Help in macro coding (https://www.excelbanter.com/excel-discussion-misc-queries/259749-help-macro-coding.html)

Sasikiran

Help in macro coding
 
Dear,

I am working on a macro which trims the raw data into a desired one.

i would require your help in adding the macro code to delete the entire row
if it does not matches to my requirement.

Say Column D has data which gives the name of the individuals. I would only
require the rows which has the below mentioned names in the column D. Like
John, Peter, Sandra and Kate.

The macro code should identify these names, keep the rows having these and
delete all other rows which do not match to these names.

Please help.

Don Guillett[_2_]

Help in macro coding
 
As ALWAYS, post your coding efforts for comments and suggestions.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Sasikiran" wrote in message
...
Dear,

I am working on a macro which trims the raw data into a desired one.

i would require your help in adding the macro code to delete the entire
row
if it does not matches to my requirement.

Say Column D has data which gives the name of the individuals. I would
only
require the rows which has the below mentioned names in the column D. Like
John, Peter, Sandra and Kate.

The macro code should identify these names, keep the rows having these and
delete all other rows which do not match to these names.

Please help.



Mike H

Help in macro coding
 
Hi,

try this

Sub Versive()
Dim R As Range
Dim V As Variant
Dim S As String
Dim CopyRange As Range
Dim LastRow As Long
Set Sht = Sheets("Sheet1") ' Change to suit
LastRow = Sht.Cells(Cells.Rows.Count, "D").End(xlUp).Row
S = "Peter,Sandra,Kate"
V = Split(S, ",")
For Each R In Sht.Range("D1:D" & LastRow)
If IsError(Application.Match(CStr(R.Value), V, 0)) Then
If CopyRange Is Nothing Then
Set CopyRange = R.EntireRow
Else
Set CopyRange = Union(CopyRange, R.EntireRow)
End If
End If
Next R

If Not CopyRange Is Nothing Then
CopyRange.Delete
End If

End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Sasikiran" wrote:

Dear,

I am working on a macro which trims the raw data into a desired one.

i would require your help in adding the macro code to delete the entire row
if it does not matches to my requirement.

Say Column D has data which gives the name of the individuals. I would only
require the rows which has the below mentioned names in the column D. Like
John, Peter, Sandra and Kate.

The macro code should identify these names, keep the rows having these and
delete all other rows which do not match to these names.

Please help.


Sasikiran

Help in macro coding
 
Thank you so much it is working :)

"Mike H" wrote:

Hi,

try this

Sub Versive()
Dim R As Range
Dim V As Variant
Dim S As String
Dim CopyRange As Range
Dim LastRow As Long
Set Sht = Sheets("Sheet1") ' Change to suit
LastRow = Sht.Cells(Cells.Rows.Count, "D").End(xlUp).Row
S = "Peter,Sandra,Kate"
V = Split(S, ",")
For Each R In Sht.Range("D1:D" & LastRow)
If IsError(Application.Match(CStr(R.Value), V, 0)) Then
If CopyRange Is Nothing Then
Set CopyRange = R.EntireRow
Else
Set CopyRange = Union(CopyRange, R.EntireRow)
End If
End If
Next R

If Not CopyRange Is Nothing Then
CopyRange.Delete
End If

End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Sasikiran" wrote:

Dear,

I am working on a macro which trims the raw data into a desired one.

i would require your help in adding the macro code to delete the entire row
if it does not matches to my requirement.

Say Column D has data which gives the name of the individuals. I would only
require the rows which has the below mentioned names in the column D. Like
John, Peter, Sandra and Kate.

The macro code should identify these names, keep the rows having these and
delete all other rows which do not match to these names.

Please help.



All times are GMT +1. The time now is 08:17 PM.

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