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

I am writing a VB application that builds a function call as a string
and pastes it into a cell. I can get get Excel to do one of two things:

(i) Evaluate it as a cell: look in that spot for values.

(ii) Evaluate it as a string giving a #name error.

As an example:

Sub Tester()
Dim myRng As Range, sCell As String
Dim myfunc As String
sCell = "F19"
Set myRng = Range(sCell)

' this one places the value from F19 into the call
myfunc = "=Sum(" + myRng + ")"
' this one places the string 'F19' into the call
myfunc = "=Sum(" + sCell + ")"

ActiveCell.FormulaR1C1 = myfunc
End Sub

So, assuming I have the value 39 in cell F19, I either get =SUM(39) in
the target cell, or =SUM('F19'). What I want is =SUM(F19).

Any ideas?

Peter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Cell strings as cells

myfunc = "=Sum(" & sCell & ")"


--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
I am writing a VB application that builds a function call as a string
and pastes it into a cell. I can get get Excel to do one of two things:

(i) Evaluate it as a cell: look in that spot for values.

(ii) Evaluate it as a string giving a #name error.

As an example:

Sub Tester()
Dim myRng As Range, sCell As String
Dim myfunc As String
sCell = "F19"
Set myRng = Range(sCell)

' this one places the value from F19 into the call
myfunc = "=Sum(" + myRng + ")"
' this one places the string 'F19' into the call
myfunc = "=Sum(" + sCell + ")"

ActiveCell.FormulaR1C1 = myfunc
End Sub

So, assuming I have the value 39 in cell F19, I either get =SUM(39) in
the target cell, or =SUM('F19'). What I want is =SUM(F19).

Any ideas?

Peter



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Cell strings as cells

While the consensus is that one uses & for concatenation and reserves +
for arithmetic addition, that is not the issue here.

You are specifing F39 in a formula entered through FormulaR1C1! Use
the correct syntax and XL will buy it just A-OK.

ActiveCell.Formula = myfunc

or, for an absolute reference to F19,

sCell = "R19C6"
myfunc = "=Sum(" + sCell + ")"
ActiveCell.FormulaR1C1 = myfunc

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article .com,
says...
I am writing a VB application that builds a function call as a string
and pastes it into a cell. I can get get Excel to do one of two things:

(i) Evaluate it as a cell: look in that spot for values.

(ii) Evaluate it as a string giving a #name error.

As an example:

Sub Tester()
Dim myRng As Range, sCell As String
Dim myfunc As String
sCell = "F19"
Set myRng = Range(sCell)

' this one places the value from F19 into the call
myfunc = "=Sum(" + myRng + ")"
' this one places the string 'F19' into the call
myfunc = "=Sum(" + sCell + ")"

ActiveCell.FormulaR1C1 = myfunc
End Sub

So, assuming I have the value 39 in cell F19, I either get =SUM(39) in
the target cell, or =SUM('F19'). What I want is =SUM(F19).

Any ideas?

Peter


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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
how do i separate 2 strings of a cell in different cells? Bona Excel Worksheet Functions 1 July 26th 07 11:32 AM
Help with removing certain strings from cells sparkroms Excel Discussion (Misc queries) 2 July 25th 06 06:14 AM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
HOW TO EXTRACT STRINGS FROM CELLS vidhya Excel Discussion (Misc queries) 2 November 17th 05 12:40 PM


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