Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default returning formula into a cell

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default returning formula into a cell

You want the row?

Just use

ActiveCell.Offset(2, 0).Value = ActiveCell.Row

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"RiverGully" wrote in message
...
I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not
the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default returning formula into a cell

Try this...

Sub test()

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
LastLineAddress = Replace(LastLineAddress, "$", "")
ActiveCell.Offset(2, 0).Formula = "=mid(" & (LastLineAddress) & ",5,2)"

End Sub

--
HTH...

Jim Thomlinson


"RiverGully" wrote:

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default returning formula into a cell

or if you want to be really concise you can do it all in just one line with
no variable...

ActiveCell.Offset(2, 0).Formula = "=mid(" & _
(Replace(ActiveCell.Address, "$", "")) & ",5,2)"

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Try this...

Sub test()

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
LastLineAddress = Replace(LastLineAddress, "$", "")
ActiveCell.Offset(2, 0).Formula = "=mid(" & (LastLineAddress) & ",5,2)"

End Sub

--
HTH...

Jim Thomlinson


"RiverGully" wrote:

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default returning formula into a cell


does changing this line help?

ActiveCell.Formula = "=mid(" & (LastLineAddress) & ",5,2)"
--


Gary


"RiverGully" wrote in message
...
I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default returning formula into a cell

Thank you very much - I'm over that hurdle now :)

"Jim Thomlinson" wrote:

Try this...

Sub test()

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
LastLineAddress = Replace(LastLineAddress, "$", "")
ActiveCell.Offset(2, 0).Formula = "=mid(" & (LastLineAddress) & ",5,2)"

End Sub

--
HTH...

Jim Thomlinson


"RiverGully" wrote:

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default returning formula into a cell

Hi Jim,

Could you help with a related question to this solution?

I need to concatenate the letter 'n' to the result of the formula:
=+mid(C149.5,2)&"n"

I'm not succeeding in trying to add the &"n" at the end of the first formula
(keep getting debug error). Can you advise once more? Thank you again!

"Jim Thomlinson" wrote:

Try this...

Sub test()

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
LastLineAddress = Replace(LastLineAddress, "$", "")
ActiveCell.Offset(2, 0).Formula = "=mid(" & (LastLineAddress) & ",5,2)"

End Sub

--
HTH...

Jim Thomlinson


"RiverGully" wrote:

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many thanks.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default returning formula into a cell

Try this...

ActiveCell.Offset(2, 0).Formula = "=mid(" & _
(Replace(ActiveCell.Address, "$", "")) & ",5,2) & ""n"""

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

or if you want to be really concise you can do it all in just one line with
no variable...

ActiveCell.Offset(2, 0).Formula = "=mid(" & _
(Replace(ActiveCell.Address, "$", "")) & ",5,2)"

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Try this...

Sub test()

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
LastLineAddress = Replace(LastLineAddress, "$", "")
ActiveCell.Offset(2, 0).Formula = "=mid(" & (LastLineAddress) & ",5,2)"

End Sub

--
HTH...

Jim Thomlinson


"RiverGully" wrote:

I would like to return the results of a formula into a cell based on an
address that I've stored in code. Unfortunately, the result does not
provide me with a value from the formula.

Here is the code I've typed:

Dim LastLineAddress As String

LastLineAddress = ActiveCell.Address
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "+mid(" & (LastLineAddress) & ",5,2)"

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 +mid($C$149,5,2)

What I was hoping for in Cell C151 was the value 56 to be displayed, not the
string +mid($C$149,5,2). Also I'd prefer not to have the absolute
references ($) in the formula.

Can you help me out? Many 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
need formula returning a blank cell vdmbqb Excel Discussion (Misc queries) 4 November 28th 09 04:51 PM
VLookup returning #N/A when looking up a cell that has a Formula i mickn74 Excel Discussion (Misc queries) 3 July 28th 09 08:14 AM
Returning the formula in another cell gelert Excel Worksheet Functions 2 September 6th 05 01:48 AM
Returning the formula in a cell Sukhjeet Excel Discussion (Misc queries) 0 June 29th 05 11:24 AM
Returning value of a cell containing a formula Ian Bayly Excel Programming 1 November 28th 03 11:16 PM


All times are GMT +1. The time now is 06:40 PM.

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"