Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Clearing only cells w/ numbers

I have a for loop that I want to clear only cells w/ numbers and not cells
that contain formulas or text. The following ignores cells w/ text, but
clear formulas.
If IsNumeric(Sheets(ToSheet).Range("List1").Rows(i)) Then
Sheets(ToSheet).Range("List1").Rows(i).ClearConten ts
End If
How do I test for for a formula in a cell?

I appreciate your help, -John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Clearing only cells w/ numbers

DIM rSource as Range

SET rSource = somerange
if LEFT(TRIM(rSource.Formula),1)="=" Then
'' its a formula -- leave it
end if

"John" wrote:

I have a for loop that I want to clear only cells w/ numbers and not cells
that contain formulas or text. The following ignores cells w/ text, but
clear formulas.
If IsNumeric(Sheets(ToSheet).Range("List1").Rows(i)) Then
Sheets(ToSheet).Range("List1").Rows(i).ClearConten ts
End If
How do I test for for a formula in a cell?

I appreciate your help, -John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Clearing only cells w/ numbers

Try

ActiveCell.HasFormula

looping through cells one by one.


Regards,
Stefi

John ezt *rta:

I have a for loop that I want to clear only cells w/ numbers and not cells
that contain formulas or text. The following ignores cells w/ text, but
clear formulas.
If IsNumeric(Sheets(ToSheet).Range("List1").Rows(i)) Then
Sheets(ToSheet).Range("List1").Rows(i).ClearConten ts
End If
How do I test for for a formula in a cell?

I appreciate your help, -John


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Clearing only cells w/ numbers

Use the HasFormula property of the range to see if it contains a formula or
not. I would also consider using a With...End With block to cut down on the
lengthy repeats. Try this...

With Sheets(ToSheet).Range("List1").
If IsNumeric(.Rows(i).Value) And Not .Rows(i).HasFormula Then
.Rows(i).ClearContents
End If
End With

--
Rick (MVP - Excel)


"John" wrote in message
...
I have a for loop that I want to clear only cells w/ numbers and not cells
that contain formulas or text. The following ignores cells w/ text, but
clear formulas.
If IsNumeric(Sheets(ToSheet).Range("List1").Rows(i)) Then
Sheets(ToSheet).Range("List1").Rows(i).ClearConten ts
End If
How do I test for for a formula in a cell?

I appreciate your help, -John



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Clearing only cells w/ numbers

Is list1 a range with more than one column?

If it is, then
IsNumeric(Sheets(ToSheet).Range("List1").Rows(i))
won't work

isnumeric() wants to work on a single cell (to make any sense anyway).

But if you just wanted to clear the cells that contain numbers and no formulas,
you could use something like:

Option Explicit
Sub testme()
Dim myNumberVals As Range
Dim myRng As Range
Dim ToSheet As String

ToSheet = "Sheet1"

Set myRng = Worksheets(ToSheet).Range("List1")

Set myNumberVals = Nothing
On Error Resume Next
Set myNumberVals = Intersect(myRng, _
myRng.SpecialCells(xlCellTypeConstants, xlNumbers))
On Error GoTo 0

If myNumberVals Is Nothing Then
'msgbox "No constant numbers!
Else
myNumberVals.ClearContents
End If

End Sub

You could get the same kind of code by:
selecting the List1 range
Hitting ctrl-g (or F5 or Edit|Goto)
then Special
Then Constants
and unchecking everything but numbers (uncheck text, logicals and errors).




John wrote:

I have a for loop that I want to clear only cells w/ numbers and not cells
that contain formulas or text. The following ignores cells w/ text, but
clear formulas.
If IsNumeric(Sheets(ToSheet).Range("List1").Rows(i)) Then
Sheets(ToSheet).Range("List1").Rows(i).ClearConten ts
End If
How do I test for for a formula in a cell?

I appreciate your help, -John


--

Dave Peterson


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
Clearing cells without clearing formulas marsjune68 Excel Discussion (Misc queries) 2 April 10th 09 07:39 PM
Clearing numbers in excel Kevin W[_2_] Excel Discussion (Misc queries) 3 September 9th 08 02:43 PM
Clearing Cells plh Excel Programming 5 October 1st 07 07:12 PM
Clearing Cells mully New Users to Excel 3 May 19th 05 07:12 PM
Clearing cells of numbers, but not cell references. Richard Buttrey[_5_] Excel Programming 1 August 5th 04 12:51 PM


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