Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Macro Delete cell if value

Hello Community:

I several columns of data. I need an excel macro that will look at a
specified column (I:I) and delete all cells that are a value I specify.
Each column of data will have a different criteria, so I'll just paste one
code after the next and change the column name and criteria.

I've looked through the discussion and can only find code to delete entire
row. I tried to modify the code to just delete cells and it did not work.

Can anyone help?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Macro Delete cell if value

Right click the sheet tab, view code and past this in and run it

Simply change MyColumn & MyValue to the required column and value to delete
If MyValue is a string then put it in Quotes""

Sub marine()
Dim MyColumn As String
Dim MyRange As Range, MyRange1 As Range
MyColumn = "I"
myvalue = 222
lastrow = Cells(Rows.Count, MyColumn).End(xlUp).Row
Set MyRange = Range(MyColumn & "1:" & MyColumn & lastrow)
For Each c In MyRange
If (c.Value) = myvalue Then
If MyRange1 Is Nothing Then
Set MyRange1 = c
Else
Set MyRange1 = Union(MyRange1, c)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

Mike

"Sojo" wrote:

Hello Community:

I several columns of data. I need an excel macro that will look at a
specified column (I:I) and delete all cells that are a value I specify.
Each column of data will have a different criteria, so I'll just paste one
code after the next and change the column name and criteria.

I've looked through the discussion and can only find code to delete entire
row. I tried to modify the code to just delete cells and it did not work.

Can anyone help?

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Macro Delete cell if value

On reflection you may want this

MyRange1.clearcontents

instead of

MyRange1.Delete

Mike


"Mike H" wrote:

Right click the sheet tab, view code and past this in and run it

Simply change MyColumn & MyValue to the required column and value to delete
If MyValue is a string then put it in Quotes""

Sub marine()
Dim MyColumn As String
Dim MyRange As Range, MyRange1 As Range
MyColumn = "I"
myvalue = 222
lastrow = Cells(Rows.Count, MyColumn).End(xlUp).Row
Set MyRange = Range(MyColumn & "1:" & MyColumn & lastrow)
For Each c In MyRange
If (c.Value) = myvalue Then
If MyRange1 Is Nothing Then
Set MyRange1 = c
Else
Set MyRange1 = Union(MyRange1, c)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

Mike

"Sojo" wrote:

Hello Community:

I several columns of data. I need an excel macro that will look at a
specified column (I:I) and delete all cells that are a value I specify.
Each column of data will have a different criteria, so I'll just paste one
code after the next and change the column name and criteria.

I've looked through the discussion and can only find code to delete entire
row. I tried to modify the code to just delete cells and it did not work.

Can anyone help?

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Macro Delete cell if value

Hi Mike H:

I tried, but it didn't run. All I did was change Mycolumn to "A", Myvalue
to 6 (no quotes) and Range(MyColumn & "1:" to 6. In other words clear values
that in column A (starting from row 6 to that last row) that are greater than
6. I hit the play button and nothing happens. I even went back to sheet 1
and tired running it from the tools, macro menus. Nothing.

Also or other columns I am going to need to use less than (<) a value, and
between 2 values (<8 but 4).

I'm using Excel 2003.

Thanks!


"Mike H" wrote:

On reflection you may want this

MyRange1.clearcontents

instead of

MyRange1.Delete

Mike


"Mike H" wrote:

Right click the sheet tab, view code and past this in and run it

Simply change MyColumn & MyValue to the required column and value to delete
If MyValue is a string then put it in Quotes""

Sub marine()
Dim MyColumn As String
Dim MyRange As Range, MyRange1 As Range
MyColumn = "I"
myvalue = 222
lastrow = Cells(Rows.Count, MyColumn).End(xlUp).Row
Set MyRange = Range(MyColumn & "1:" & MyColumn & lastrow)
For Each c In MyRange
If (c.Value) = myvalue Then
If MyRange1 Is Nothing Then
Set MyRange1 = c
Else
Set MyRange1 = Union(MyRange1, c)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

Mike

"Sojo" wrote:

Hello Community:

I several columns of data. I need an excel macro that will look at a
specified column (I:I) and delete all cells that are a value I specify.
Each column of data will have a different criteria, so I'll just paste one
code after the next and change the column name and criteria.

I've looked through the discussion and can only find code to delete entire
row. I tried to modify the code to just delete cells and it did not work.

Can anyone help?

Thanks!

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
How do I creat a macro to delete the first 20 cell characters Bobo-ack Excel Worksheet Functions 5 April 20th 07 03:00 AM
create macro - if cell is 0 delete row pywhacket Excel Worksheet Functions 1 March 15th 06 03:55 PM
VBA Excel Macro to delete contents in named cell reaa Excel Discussion (Misc queries) 1 January 3rd 06 08:16 PM
Delete Row Macro - if cell $5000 Danny Excel Worksheet Functions 1 October 25th 05 07:52 PM
set up a macro to delete characters in each cell of a column Rick Excel Discussion (Misc queries) 2 September 18th 05 03:02 AM


All times are GMT +1. The time now is 05:36 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"