sorting code problems

  • Thread starter Thread starter DKY
  • Start date Start date
D

DKY

Here's what I got, and needless to say attributing to my extreme lack o
experience its not working. any suggestions?

Dim rng As Range, sStr As String, i As Long
Set rng = Cells(A, 65536).End(xlToLeft)
For i = rng.Row To 1 Step -1
sStr = LCase(Cells(1, i).Value)
If sStr <> "26" Then
Cells(A, i).EntireRow.Delete
End If
Nex
 
Sub DeleteData()
Dim rng As Range, rng1 As Range
Set rng = Range(Cells(2, "C"), Cells(Rows.Count, "C").End(xlUp))
For Each cell In rng
If cell.Value <> 26 Then
If rng1 Is Nothing Then
Set rng1 = cell
Else
Set rng1 = Union(rng1, cell)
End If
End If
Next
If Not rng1 Is Nothing Then
rng1.EntireRow.Delete
End If
End Sub


or

Sub DeleteRows()
Dim rng As Range, rng1 As Range
Range("C1").CurrentRegion.AutoFilter _
Field:=3, Criteria1:="<>26", Operator:=xlAnd
Set rng = Intersect(ActiveSheet.AutoFilter.Range, Columns(3))
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1, 1)
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1.EntireRow.Delete
End If
ActiveSheet.ShowAllData
Range("C1").CurrentRegion.AutoFilter
End Sub

Should do it.
 
I think this wil work for you (different approach):

Dim RowNo as Long

RowNo = Range("A1").CurrentRegion.Rows.Count
While RowNo > 0
With Range("A" & RowNo)
If LCase(.Value) <> "26" Then .EntireRow.Delete
End With
RowNo = RowNo - 1
Wend
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top