Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default select fields with more then one dash (-)

I have 40,000 records and need to delete the ones that contain more then one
dash. For example:
1 k-90
2 k-90-1
3 k-50
4 k-50-1
5 k-50-1-a

I need to select fields 2,4, and 5 so I can get rid of them

Any advice on how to do this? thank you!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default select fields with more then one dash (-)

Assuming the data is in column B and there are no blank lines and the format
of the data is consistent then the following should work.

Sub DeleteRows()

Dim inputcell As Range
Dim nextcell As Range

Set inputcell = Worksheets(1).Range("B2")

Do Until IsEmpty(inputcell.Value)
Set nextcell = inputcell.Offset(1)
If inputcell.Value Like "?-??-*" Then
inputcell.EntireRow.Delete
End If

Set inputcell = nextcell
Loop

End Sub


"Knox" wrote:

I have 40,000 records and need to delete the ones that contain more then one
dash. For example:
1 k-90
2 k-90-1
3 k-50
4 k-50-1
5 k-50-1-a

I need to select fields 2,4, and 5 so I can get rid of them

Any advice on how to do this? thank you!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default select fields with more then one dash (-)

Give this a whirl...

Sub DeleteMultiDash()
Dim rngToSearch As Range
Dim rngToDelete As Range
Dim rng As Range

With Sheets("Sheet1")
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))
End With

For Each rng In rngToSearch
If Len(rng) = Len(Replace(rng, "-", "")) + 2 Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
--
HTH...

Jim Thomlinson


"Knox" wrote:

I have 40,000 records and need to delete the ones that contain more then one
dash. For example:
1 k-90
2 k-90-1
3 k-50
4 k-50-1
5 k-50-1-a

I need to select fields 2,4, and 5 so I can get rid of them

Any advice on how to do this? thank you!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default select fields with more then one dash (-)

yea that worked real well! thanx

"Jim Thomlinson" wrote:

Give this a whirl...

Sub DeleteMultiDash()
Dim rngToSearch As Range
Dim rngToDelete As Range
Dim rng As Range

With Sheets("Sheet1")
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))
End With

For Each rng In rngToSearch
If Len(rng) = Len(Replace(rng, "-", "")) + 2 Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
--
HTH...

Jim Thomlinson


"Knox" wrote:

I have 40,000 records and need to delete the ones that contain more then one
dash. For example:
1 k-90
2 k-90-1
3 k-50
4 k-50-1
5 k-50-1-a

I need to select fields 2,4, and 5 so I can get rid of them

Any advice on how to do this? thank you!

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 replace/select new fields in pivot table using a macro? snowdog Excel Discussion (Misc queries) 1 August 4th 09 03:58 AM
Not able to select Calculated Fields for Pivot Tables jchang320 Excel Worksheet Functions 0 June 19th 08 08:50 PM
Tabbing to select fields Confused Excel Worksheet Functions 2 May 12th 08 04:26 PM
Since SP2, my pivot tables cannot select various fields tlld Excel Discussion (Misc queries) 3 November 1st 06 10:39 PM
understanding dash dash in a excel formula ldebner Excel Worksheet Functions 2 October 31st 05 01:47 PM


All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"