Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help on macro coding for URL | Excel Worksheet Functions | |||
Please help on coding the macro. | Excel Worksheet Functions | |||
HELP - coding on Macro! | Excel Worksheet Functions | |||
coding macro | Excel Discussion (Misc queries) | |||
How to use the if statement for Macro coding? | Excel Worksheet Functions |