Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Delete cells if

Morning,

Could some please give me a macro that will delete the contents of any cells
in the range A1 to F100 if the value in the corresponding F cell = 0. So the
table would look like

A B C D E F
xx yy aa pp 1
dd aa uu rr 1
oo kk rr ee 0
kk mm nn gg 0

and i would like the macro to delete A3:F4. All the the list will be a
continous string of 1's followed by a break to zero then a continous list of
zero's, it will not read 1 1 1 0 1 0 1 for example, only 1 1 1 1 0 0 0

Thanks
LiAD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Delete cells if

If you mean to delete the rows with ColF 0 try the below

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Morning,

Could some please give me a macro that will delete the contents of any cells
in the range A1 to F100 if the value in the corresponding F cell = 0. So the
table would look like

A B C D E F
xx yy aa pp 1
dd aa uu rr 1
oo kk rr ee 0
kk mm nn gg 0

and i would like the macro to delete A3:F4. All the the list will be a
continous string of 1's followed by a break to zero then a continous list of
zero's, it will not read 1 1 1 0 1 0 1 for example, only 1 1 1 1 0 0 0

Thanks
LiAD

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Delete cells if

Hi,

Sorry this is deleting the whole row.

I was looking for something that just deletes the contents of cells A to F.

Thanks again

"Jacob Skaria" wrote:

If you mean to delete the rows with ColF 0 try the below

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Morning,

Could some please give me a macro that will delete the contents of any cells
in the range A1 to F100 if the value in the corresponding F cell = 0. So the
table would look like

A B C D E F
xx yy aa pp 1
dd aa uu rr 1
oo kk rr ee 0
kk mm nn gg 0

and i would like the macro to delete A3:F4. All the the list will be a
continous string of 1's followed by a break to zero then a continous list of
zero's, it will not read 1 1 1 0 1 0 1 for example, only 1 1 1 1 0 0 0

Thanks
LiAD

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Delete cells if

Try the below...

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then
'To clear contents
Range("A" & lngRow & ":F" & lngRow).ClearContents

'To shift the cells up without deleting the entire row
'Range("A" & lngRow & ":F" & lngRow).Delete Shift:=xlUp
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Hi,

Sorry this is deleting the whole row.

I was looking for something that just deletes the contents of cells A to F.

Thanks again

"Jacob Skaria" wrote:

If you mean to delete the rows with ColF 0 try the below

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Morning,

Could some please give me a macro that will delete the contents of any cells
in the range A1 to F100 if the value in the corresponding F cell = 0. So the
table would look like

A B C D E F
xx yy aa pp 1
dd aa uu rr 1
oo kk rr ee 0
kk mm nn gg 0

and i would like the macro to delete A3:F4. All the the list will be a
continous string of 1's followed by a break to zero then a continous list of
zero's, it will not read 1 1 1 0 1 0 1 for example, only 1 1 1 1 0 0 0

Thanks
LiAD

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Delete cells if

Perfecto

Cheers

"Jacob Skaria" wrote:

Try the below...

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then
'To clear contents
Range("A" & lngRow & ":F" & lngRow).ClearContents

'To shift the cells up without deleting the entire row
'Range("A" & lngRow & ":F" & lngRow).Delete Shift:=xlUp
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Hi,

Sorry this is deleting the whole row.

I was looking for something that just deletes the contents of cells A to F.

Thanks again

"Jacob Skaria" wrote:

If you mean to delete the rows with ColF 0 try the below

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "F").End(xlUp).Row To 1 Step -1
If Range("F" & lngRow).Text = "0" Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Morning,

Could some please give me a macro that will delete the contents of any cells
in the range A1 to F100 if the value in the corresponding F cell = 0. So the
table would look like

A B C D E F
xx yy aa pp 1
dd aa uu rr 1
oo kk rr ee 0
kk mm nn gg 0

and i would like the macro to delete A3:F4. All the the list will be a
continous string of 1's followed by a break to zero then a continous list of
zero's, it will not read 1 1 1 0 1 0 1 for example, only 1 1 1 1 0 0 0

Thanks
LiAD



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 do I merge cells into one then delete the original cells? LLR Excel Worksheet Functions 2 March 7th 08 10:59 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 02:58 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"