Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default delete code needed

The following code (see below) I run after I paste a list
of used telephone extensions into column A. The range of
numbers is 6000 to 6299. Based on the column A data, the
code returns a list of the unused extensions (the gaps in
the data list).
So if I paste in column A:
6000
6002
6005
..
..
..
it will display in column C:
6001
6003
6004
etc

The problem I am having is that the original list I paste
in can have virtual numbers, such as 6*002 and 60*03. For
my purposes, these numbers do not need to be counted. My
current code crashes though until I manually delete these
numbers from the original list - which can take a lot of
time.
Does anyone know of a piece of code that I can run before
the main code below that will automatically delete any
number that has a * character from the list in column A?
Once I have a clean list of numbers, I can then run the
code below as I normally do. If it's easier to have this
newly edited list displayed in column B, that would be
fine too.
Any help on this would be fantastic.
Thanks.
-----------


Sub DisplayMissing_150()
Dim C As Range, V As Variant
Dim prev&, k&, n&

k = 1
prev = 5999 ' one less than beginning, here 6000
For Each C In Intersect(Range("A:A"),
ActiveSheet.UsedRange)
If C prev + 1 Then ' some numbers left
V = Evaluate("Row(" & prev + 1 & ":" & C - 1 & ")")
n = C - (prev + 1)
Cells(k, "C").Resize(n, 1) = V
k = k + n
End If
prev = C
Next C

' do the last ones, aka from the highest to 6299
If prev < 6299 Then
V = Evaluate("Row(" & prev + 1 & ":6299)")
n = 6299 - prev
Cells(k, "C").Resize(n, 1) = V
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default delete code needed

Maybe applying data|filter|autofilter, filtering to show only those cells that
contain ~* (* is a wild card, the ~ means to look for the real asterisk), then
delete the visible rows:

Option Explicit

Sub testme()
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.AutoFilterMode = False
.Range("a:a").AutoFilter Field:=1, Criteria1:="=*~**"
With .AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible) _
.Cells.Count 1 Then
.Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible).EntireRow.D elete
End If
End With
.AutoFilterMode = False
End With

End Sub

Rick wrote:

The following code (see below) I run after I paste a list
of used telephone extensions into column A. The range of
numbers is 6000 to 6299. Based on the column A data, the
code returns a list of the unused extensions (the gaps in
the data list).
So if I paste in column A:
6000
6002
6005
.
.
.
it will display in column C:
6001
6003
6004
etc

The problem I am having is that the original list I paste
in can have virtual numbers, such as 6*002 and 60*03. For
my purposes, these numbers do not need to be counted. My
current code crashes though until I manually delete these
numbers from the original list - which can take a lot of
time.
Does anyone know of a piece of code that I can run before
the main code below that will automatically delete any
number that has a * character from the list in column A?
Once I have a clean list of numbers, I can then run the
code below as I normally do. If it's easier to have this
newly edited list displayed in column B, that would be
fine too.
Any help on this would be fantastic.
Thanks.
-----------

Sub DisplayMissing_150()
Dim C As Range, V As Variant
Dim prev&, k&, n&

k = 1
prev = 5999 ' one less than beginning, here 6000
For Each C In Intersect(Range("A:A"),
ActiveSheet.UsedRange)
If C prev + 1 Then ' some numbers left
V = Evaluate("Row(" & prev + 1 & ":" & C - 1 & ")")
n = C - (prev + 1)
Cells(k, "C").Resize(n, 1) = V
k = k + n
End If
prev = C
Next C

' do the last ones, aka from the highest to 6299
If prev < 6299 Then
V = Evaluate("Row(" & prev + 1 & ":6299)")
n = 6299 - prev
Cells(k, "C").Resize(n, 1) = V
End If

End Sub


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default delete code needed

Thanks for your help with this, Dave. Your code worked
perfectly.
Thanks again.


-----Original Message-----
Maybe applying data|filter|autofilter, filtering to show

only those cells that
contain ~* (* is a wild card, the ~ means to look for the

real asterisk), then
delete the visible rows:

Option Explicit

Sub testme()
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
.AutoFilterMode = False
.Range("a:a").AutoFilter Field:=1,

Criteria1:="=*~**"
With .AutoFilter.Range
If .Columns(1).Cells.SpecialCells

(xlCellTypeVisible) _
.Cells.Count 1 Then
.Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells

(xlCellTypeVisible).EntireRow.Delete
End If
End With
.AutoFilterMode = False
End With

End Sub

Rick wrote:

The following code (see below) I run after I paste a

list
of used telephone extensions into column A. The range

of
numbers is 6000 to 6299. Based on the column A data, the
code returns a list of the unused extensions (the gaps

in
the data list).
So if I paste in column A:
6000
6002
6005
.
.
.
it will display in column C:
6001
6003
6004
etc

The problem I am having is that the original list I

paste
in can have virtual numbers, such as 6*002 and 60*03.

For
my purposes, these numbers do not need to be counted.

My
current code crashes though until I manually delete

these
numbers from the original list - which can take a lot of
time.
Does anyone know of a piece of code that I can run

before
the main code below that will automatically delete any
number that has a * character from the list in column A?
Once I have a clean list of numbers, I can then run the
code below as I normally do. If it's easier to have this
newly edited list displayed in column B, that would be
fine too.
Any help on this would be fantastic.
Thanks.
-----------

Sub DisplayMissing_150()
Dim C As Range, V As Variant
Dim prev&, k&, n&

k = 1
prev = 5999 ' one less than beginning, here 6000
For Each C In Intersect(Range("A:A"),
ActiveSheet.UsedRange)
If C prev + 1 Then ' some numbers left
V = Evaluate("Row(" & prev + 1 & ":" & C - 1

& ")")
n = C - (prev + 1)
Cells(k, "C").Resize(n, 1) = V
k = k + n
End If
prev = C
Next C

' do the last ones, aka from the highest to 6299
If prev < 6299 Then
V = Evaluate("Row(" & prev + 1 & ":6299)")
n = 6299 - prev
Cells(k, "C").Resize(n, 1) = V
End If

End Sub


--

Dave Peterson

.

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
VBA code help needed Martin Excel Discussion (Misc queries) 3 April 28th 06 09:28 AM
Code Help Needed Michael168[_116_] Excel Programming 2 September 18th 04 05:28 PM
Better code needed ceplane Excel Programming 6 May 10th 04 07:59 PM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM
VBA code to delete VBA code in another Workbook Chip Pearson Excel Programming 0 September 15th 03 03:54 PM


All times are GMT +1. The time now is 03:04 AM.

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"