![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 16
|
I need to clear all cells in a column that have a particular value. The value is sometimes a constant like "0" (zero) and sometimes is a value based on a formula. Is there a VBA code that will allow me to select those cells in column matching a particular value and clear them?
Cheers |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Posts: 3,065
|
why use vba find and replace
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#3 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
This should work on formulae results or values:
Code:
Sub deltime() For Each Cell In [a:a] If Cell.Value = "0" Then Cell.ClearContents 'put any value you want here Next Cell End Sub _________________ Cheers, NateO "Me no are no nice guy." [ This Message was edited by: NateO on 2002-04-25 15:49 ] |
|
|
|
|
|
#4 |
|
New Member
Join Date: Apr 2002
Posts: 16
|
Thanks guys, that worked fine
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Aug 2009
Posts: 116
|
This looks really helpful, when i try is though i get
Run Time Error 13: "Type Mismatch" and the below is highlighted If Cell.Value = "00/01/1900" Then I have tried changing the month and day around and also tried changing it to "ben" and the same error occurs. Secondly, will this work on a VLOOKUP result, which 00/01/1900 is Thanks Ben PS. I've tried this on some other columns and managed to get it mostly working, it seems the VLOOKUP result is scuppering things, any suggestions? Last edited by Bench; Sep 29th, 2009 at 09:06 AM. Reason: Additional info |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Sep 2005
Posts: 135
|
that code won't work for a vlookup result. to do that you need to copy the vlookup result and paste it as a value. so if column A is your vlookup column, I'd copy and paste column A onto itself as values and then do a find/replace for specific values.
|
|
|
|
|
|
#7 |
|
MrExcel MVP
Moderator They call me "Mary" Join Date: May 2008
Location: In the flat field
Posts: 16,243
|
Do you have any error values in your data? You will get a Type Mismatch error if you try and compare error values like that.
__________________
Rory Microsoft MVP - Excel. My wife treats me like a god - she ignores my existence until she wants something. |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Aug 2009
Posts: 116
|
Thanks i've tried that but still no luck, even changed from date to general, i think it may be as Rorya says, "00/01/1900" is the result i'm trying to lose, this i guess is an error as it is saying that the data in the other spreadsheet is blank.
Is there a way around this, a way to blank out the errors? and not simply changing the font to white I'm wondering also if it may be the way date is formatted within the VBA, should it be done dd/mm/yyyy or is there another format required? Last edited by Bench; Sep 29th, 2009 at 12:15 PM. Reason: additional info |
|
|
|
|
|
#9 |
|
MrExcel MVP
Moderator They call me "Mary" Join Date: May 2008
Location: In the flat field
Posts: 16,243
|
00/01/1900 is not an error. If the VLOOKUP were returning an error, you would see #N/A in the cell. You could try using:
Code:
If Cell.Value2 = 0 then
__________________
Rory Microsoft MVP - Excel. My wife treats me like a god - she ignores my existence until she wants something. |
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Sep 2005
Posts: 135
|
You could add IF logic to your VLOOKUP to evaluate if it returns #N/A or #VALUE! using the ISERROR function. It will require you to have the VLOOKUP in the cell formula more than once, so on large spreadsheets it might be a concern since the VLOOKUP is a volatile function.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|