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

I need to concatenate the letter 'n' after a formula that was returned to a
cell.


Here is the code I've typed (as helped from Jim Thomlinson):
Sub test()

Dim LastLineAddress As String

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

End Sub



Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 Formula =+mid(C149,5,2) with resultant value of 56 shown in
cell

I now need the resultant formula to read =+mid(C149,5,2)&"n" with the
resultant value being 56n.

I've tried to edit the VBA code to add this &"n", but keep getting debug
error.

Can you advise. Thank you again!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default return a concatenated formula into a cell

One way:

Option Explicit
Sub test2()

Dim LastLineAddress As String

'this will remove the $'s from the .address
LastLineAddress = ActiveCell.Address(false, false)

ActiveCell.Offset(2, 0).Formula _
= "=mid(" & LastLineAddress & ",5,2)&""n"""
End Sub

This is one of those times that working in R1C1 reference style makes it easier.

Option Explicit
Sub test2()
ActiveCell.Offset(2, 0).FormulaR1C1 = "=mid(r[-2]c,5,2)&""n"""
End Sub

In this expression: r[-2]c
r[-2] says to use two rows up from the cell getting the formula
c says to use the same column


RiverGully wrote:

I need to concatenate the letter 'n' after a formula that was returned to a
cell.

Here is the code I've typed (as helped from Jim Thomlinson):
Sub test()

Dim LastLineAddress As String

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

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 Formula =+mid(C149,5,2) with resultant value of 56 shown in
cell

I now need the resultant formula to read =+mid(C149,5,2)&"n" with the
resultant value being 56n.

I've tried to edit the VBA code to add this &"n", but keep getting debug
error.

Can you advise. Thank you again!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default return a concatenated formula into a cell

Thank you Dave. This has been very helpful to me.

"Dave Peterson" wrote:

One way:

Option Explicit
Sub test2()

Dim LastLineAddress As String

'this will remove the $'s from the .address
LastLineAddress = ActiveCell.Address(false, false)

ActiveCell.Offset(2, 0).Formula _
= "=mid(" & LastLineAddress & ",5,2)&""n"""
End Sub

This is one of those times that working in R1C1 reference style makes it easier.

Option Explicit
Sub test2()
ActiveCell.Offset(2, 0).FormulaR1C1 = "=mid(r[-2]c,5,2)&""n"""
End Sub

In this expression: r[-2]c
r[-2] says to use two rows up from the cell getting the formula
c says to use the same column


RiverGully wrote:

I need to concatenate the letter 'n' after a formula that was returned to a
cell.

Here is the code I've typed (as helped from Jim Thomlinson):
Sub test()

Dim LastLineAddress As String

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

End Sub

Here is the result in the spreadsheet:

Cell C149: 12345678
Cell C150
Cell C151 Formula =+mid(C149,5,2) with resultant value of 56 shown in
cell

I now need the resultant formula to read =+mid(C149,5,2)&"n" with the
resultant value being 56n.

I've tried to edit the VBA code to add this &"n", but keep getting debug
error.

Can you advise. Thank you again!


--

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
Concatenated formula help JimT Excel Worksheet Functions 3 January 9th 09 01:16 AM
Past Special Concatenated formula Don Excel Discussion (Misc queries) 7 December 11th 07 09:20 AM
cannot get concatenated formula to evaluate... green fox Excel Discussion (Misc queries) 2 April 25th 07 06:27 PM
concatenated text to formula Bill Elerding Excel Discussion (Misc queries) 6 May 5th 05 01:11 AM
Concatenated Formula Phil Hageman[_3_] Excel Programming 4 April 26th 04 02:32 PM


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