ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Append Selected Cell in another Cell's Formula (https://www.excelbanter.com/excel-programming/358271-append-selected-cell-another-cells-formula.html)

craigjl

Append Selected Cell in another Cell's Formula
 

Basically, I want to do the following inside a macro. The macro should
work on any selected cell, and can be used in many different
locations.

If I select C1 for example and run macro, I want the following change
made in D10:

Original D10: =F4+B5
New D10: =F4+B5+C1

I've figured out the following line of code to start with:

Range("D10").Formula = Range("D10").Formula + Selection.Cells(Row,
Column)

But it doesn't give me what I want.


--
craigjl
------------------------------------------------------------------------
craigjl's Profile: http://www.excelforum.com/member.php...o&userid=33247
View this thread: http://www.excelforum.com/showthread...hreadid=530719


craigjl[_2_]

Append Selected Cell in another Cell's Formula
 

Ok. I managed to solve part of the problem. The line:

Range("D10").Formula = Range("D10").Formula + Selection.Cells(Row,
Column)

Should use the concantenate sign "&" rather than "+":

Range("D10").Formula = Range("D10").Formula & "+" &
Selection.Cells(Row, Column)

Now I just need to get the cell referance rather than the value.


--
craigjl
------------------------------------------------------------------------
craigjl's Profile: http://www.excelforum.com/member.php...o&userid=33247
View this thread: http://www.excelforum.com/showthread...hreadid=530719


GregR

Append Selected Cell in another Cell's Formula
 
Craigjl, How about

Range("D10").Formula = Range("D10").Formula & "+" &
Selection.Cells(Row, Column).Address

Greg


craigjl[_3_]

Append Selected Cell in another Cell's Formula
 

GregR,

Thanks for the code. The .Address was the part I was missing.
However, I found that the line you provided actually gave me the
address of the cell 1 cell up and 1 cell left of the selected one. The
following line works as expected:

Range("O43").Formula = Range("O43").Formula & "+" & Selection.Cells(1,
1).Address


--
craigjl
------------------------------------------------------------------------
craigjl's Profile: http://www.excelforum.com/member.php...o&userid=33247
View this thread: http://www.excelforum.com/showthread...hreadid=530719


GregR

Append Selected Cell in another Cell's Formula
 
Craig, glad you got it working and happy to help

Greg



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com