Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default delete cells with a value of 2

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default delete cells with a value of 2

Sub RemoveCells_ShiftUp()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim rw As Long, iCol As Long
For rw = ActiveSheet.UsedRange.Rows.Count + 1 To 2 Step -1
For iCol = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
If Cells(rw - 1, iCol).Value = 2 Then
Cells(rw - 1, iCol).Delete Shift:=xlShiftUp
End If
Next iCol
Next rw
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"pgc" wrote in message
ups.com...
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



  #4   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

great thanks a lot
works a treat
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



  #5   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

Thanks Bob
works well
dont suppose you could tell me in plain english why my code didnt work
cheers paul
Bob Phillips wrote:
Sub RemoveCells_ShiftUp()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim rw As Long, iCol As Long
For rw = ActiveSheet.UsedRange.Rows.Count + 1 To 2 Step -1
For iCol = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
If Cells(rw - 1, iCol).Value = 2 Then
Cells(rw - 1, iCol).Delete Shift:=xlShiftUp
End If
Next iCol
Next rw
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"pgc" wrote in message
ups.com...
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




  #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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default delete cells with a value of 2

The biggest problem that you had was that you were walking through the whole
range, but only checking the activecell. So if activecell had the value 2,
the test passed for each cell in the range, and you cleared it.

You were also only testing column 1, so after fixing that, there was still a
problem.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"pgc" wrote in message
ups.com...
Thanks Bob
works well
dont suppose you could tell me in plain english why my code didnt work
cheers paul
Bob Phillips wrote:
Sub RemoveCells_ShiftUp()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim rw As Long, iCol As Long
For rw = ActiveSheet.UsedRange.Rows.Count + 1 To 2 Step -1
For iCol = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
If Cells(rw - 1, iCol).Value = 2 Then
Cells(rw - 1, iCol).Delete Shift:=xlShiftUp
End If
Next iCol
Next rw
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"pgc" wrote in message
ups.com...
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




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
delete cells column. Delete empty cells myshak Excel Worksheet Functions 0 March 9th 09 10:59 PM
how can I delete cells containing text within a range of cells jackwmbg Excel Discussion (Misc queries) 2 June 6th 08 09:08 PM
How to delete all the blanc cells in a worksheet and shift cells l tiramisu Excel Discussion (Misc queries) 2 December 7th 06 03:45 AM
macro to select cells containing specific text and delete all cells but these JenIT Excel Programming 3 March 27th 06 10:07 PM
Delete specific cells contents in a row with some locked cells in the same row trussman Excel Programming 2 March 1st 05 06:12 PM


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

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"