View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
pgc pgc is offline
external usenet poster
 
Posts: 11
Default delete cells with a value of 2

Cheers Kevin
Kevin B wrote:
I believe the following code will do what you want, just adjust the range of
A1:F19 accordingly.

Sub RemoveTwo()

Dim r As Range
Dim l As Long

Set r = Range("A1:F19") 'Your range goes here

For l = 1 To r.Cells.Count
If r.Cells(l) = 2 Then r.Cells(l).Delete Shift:=xlUp
Next

Set r = Nothing

End Sub
--
Kevin Backmann


"pgc" wrote:

Please help i have a sheet like this
A b c
2 fun 1
run 2 100
i want to delete the numer2 in column A and move "run" in column A to
cell A1, same in column B,C etc
i have started a code but it deletes all cells not just the ones with
the number 2 in
heres my code

Sub RemoveCells_ShiftUp()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim rw As Long, iCol As Long
For rw = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If ActiveCell.Value = 2 Then _
Cells(rw, 1).Delete Shift:=xlShiftUp
Next
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
by the way i am not very good with code
Hope someone can help