Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Skip empty and text cells

I have a range of cells that contain formulas with an
apostrophe in front. For example: '=SUM(A1:B1). I need to
evaluate the formulas. My code works with cells containing
examples like this, but returns errors if the cells are
empty or contain other text strings like "eeeee". I just
need to skip these. TIA. Jason
-----------------------------

Sub BringMyFormulasBack()

Dim cell As Range
Dim oldfrmla As String

For Each cell In Selection
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
End If
cell.Formula = Evaluate(oldfrmla)
Next cell

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Skip empty and text cells

Hi Jason:

Can't you just use a test that checks to see if the first character of the
string is "="?

If Left(oldfrmla, 1) = "=" Then cell.Formula = Evaluate(oldfrmla)

Regards,

Vasant.

"Jason Morin" wrote in message
...
I have a range of cells that contain formulas with an
apostrophe in front. For example: '=SUM(A1:B1). I need to
evaluate the formulas. My code works with cells containing
examples like this, but returns errors if the cells are
empty or contain other text strings like "eeeee". I just
need to skip these. TIA. Jason
-----------------------------

Sub BringMyFormulasBack()

Dim cell As Range
Dim oldfrmla As String

For Each cell In Selection
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
End If
cell.Formula = Evaluate(oldfrmla)
Next cell

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Skip empty and text cells

Jason,

If you move the line "cell.Formula = Evaluate(oldfrmla)" into the if block
(see my change),
the evaluation will only be attempted if the first character is and
apostrophe:

For Each cell In Selection
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
cell.Formula = Evaluate(oldfrmla)
End If
Next cell

Jeff


"Jason Morin" wrote in message
...
I have a range of cells that contain formulas with an
apostrophe in front. For example: '=SUM(A1:B1). I need to
evaluate the formulas. My code works with cells containing
examples like this, but returns errors if the cells are
empty or contain other text strings like "eeeee". I just
need to skip these. TIA. Jason
-----------------------------

Sub BringMyFormulasBack()

Dim cell As Range
Dim oldfrmla As String

For Each cell In Selection
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
End If
cell.Formula = Evaluate(oldfrmla)
Next cell

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Skip empty and text cells

Hi Jason,

What's up? Trying to hone those VBA skills to the same level as your
worksheet skills?

Here is one way

Dim cell As Range
Dim oldfrmla As String

For Each cell In Selection
If cell.HasFormula Then
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
End If
cell.Formula = Evaluate(oldfrmla)
End If
Next cell

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jason Morin" wrote in message
...
I have a range of cells that contain formulas with an
apostrophe in front. For example: '=SUM(A1:B1). I need to
evaluate the formulas. My code works with cells containing
examples like this, but returns errors if the cells are
empty or contain other text strings like "eeeee". I just
need to skip these. TIA. Jason
-----------------------------

Sub BringMyFormulasBack()

Dim cell As Range
Dim oldfrmla As String

For Each cell In Selection
oldfrmla = cell.Text
If Left(oldfrmla, 1) = Chr(39) Then
oldfrmla = Right(oldfrmla, Len(oldfrmla) - 1)
End If
cell.Formula = Evaluate(oldfrmla)
Next cell

End Sub




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
skip cells with zero values in chart (cells not empty) jhall@ifox Charts and Charting in Excel 3 June 2nd 09 02:11 PM
I want the autofill/drag function to skip empty cells tcmcgee Excel Discussion (Misc queries) 1 October 28th 08 04:27 PM
paste special / skip empty cells doesn't work!? Ivica TypeR Excel Worksheet Functions 3 July 10th 07 04:53 PM
Formula returns empty; chart plots zero; I want to skip bluegar Charts and Charting in Excel 6 March 28th 07 09:42 AM
How to skip cells with text strings. mikeburg Excel Discussion (Misc queries) 1 August 6th 05 12:52 AM


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