Macro to copy contents of one cell into another keeping original values

jtt2

New Member
Joined
Sep 19, 2023
Messages
7
Office Version
  1. 365
Anyone know how to modify this macro so that B20 shows its original value. For example, if A1=1000 and B20=500, I want to see the answer as 1,500 but if I click on the cell I want to see =1000+500?



Code:
Sub MyFormulaAdder()

Dim d As Double
d = Range("A1").Value

Range("A1").Formula = "=" & d & "+B20"

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You only need one line of code:
VBA Code:
Sub MyFormulaAdder()
    Range("A1").Formula = "=" & Range("A1").Value & "+" & Range("B20").Value
End Sub
 
Upvote 0
You only need one line of code:
VBA Code:
Sub MyFormulaAdder()
    Range("A1").Formula = "=" & Range("A1").Value & "+" & Range("B20").Value
End Sub
You only need one line of code:
VBA Code:
Sub MyFormulaAdder()
    Range("A1").Formula = "=" & Range("A1").Value & "+" & Range("B20").Value
End Sub
OMG AMAZING, thank you so much! It worked perfectly, I have another question now. How do I loop it down the column excluding rows with SUBTOTAL?
 
Upvote 0
I suggest you show us a small sample of your data and expected result, so we can see how things are all laid out.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
OMG AMAZING, thank you so much! It worked perfectly, I have another question now. How do I loop it down the column excluding rows with SUBTOTAL?
I have some cells that have references other tabs in the workbook, is there a way to keep the reference in the cell when you add them together in this macro?
 
Upvote 0
I have some cells that have references other tabs in the workbook, is there a way to keep the reference in the cell when you add them together in this macro?
Please provide an example of exactly what you are trying to do.
 
Upvote 0
<
AUA LLC Draw Request #12 9-5-23 test.xlsm
FG
4431,805.50875.00
Draw Schedule
Cell Formulas
RangeFormula
F44F44='Close Draw'!U64+'Close Draw'!U65
G44G44='Draw # 12'!E53
>
 
Upvote 0
Please walk us through an example, providing is with BEFORE and AFTER images, so we can see exactly what you are starting with and what you want for your end result.
 
Upvote 0
I would like to add cell G44 to F44 so that cell F44 is now ='Close Draw'!U64+'Close Draw'!U65+Draw # 12'!E53
 
Upvote 0
Try this:
VBA Code:
Sub MyFormulaAdder()
    
    Dim frm As String
    
'   Get formula from cell G44
    frm = Range("G44").Formula
    
'   Add formula from cell G44 to end of formula in F44
    Range("F44").Formula = Range("F44").Formula & "+" & Mid(frm, 2, Len(frm) - 1)
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top