ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   reading a formula and pasting it (https://www.excelbanter.com/excel-programming/340304-reading-formula-pasting.html)

lawson

reading a formula and pasting it
 
i would like my program below to read the cell entered, copy the FORMULA
enterinto it (ie. "=h91+h38/j34") and paste it on all the appropriate spread
sheets (those that have a 4 in the correct cell. it currently only copies the
VALUE in the cell entered...

Sub M15GoToBotRight_All()
On Error GoTo bob2
selected_cell = InputBox("Enter Destination cell")
Formula1 = MsgBox("Copy Formula?", vbYesNo + vbDefaultButton2, "Quick
fixin's")
If Formula1 = vbYes Then Range(selected_cell).Select
Formula2 = ActiveCell
For Each w In Application.Workbooks: w.Activate
If selected_cell < "" Then
If Range("Sheet1!as597") = 4 Then Range(selected_cell).Select
If Formula1 = vbYes Then ActiveCell = Formula2
Else
If Range("Sheet1!as597") = 4 Then Application.Run "M15GoToBotRight"
End If
Next w: ThisWorkbook.Activate
Exit Sub
bob2: MsgBox ("Enter a Column and Row (Ex: z45)")
End Sub

MIKE215

reading a formula and pasting it
 
Hi Lawson

Try changing the line Formula2 = activecell to
Formula2 = Activecell.Formula
then the line that says if Formula1 = vbyes then activecell = Formula2
to If Formula1 =vbyes then Activecell.formula = Formula2

regards,
Mike

"lawson" wrote:

i would like my program below to read the cell entered, copy the FORMULA
enterinto it (ie. "=h91+h38/j34") and paste it on all the appropriate spread
sheets (those that have a 4 in the correct cell. it currently only copies the
VALUE in the cell entered...

Sub M15GoToBotRight_All()
On Error GoTo bob2
selected_cell = InputBox("Enter Destination cell")
Formula1 = MsgBox("Copy Formula?", vbYesNo + vbDefaultButton2, "Quick
fixin's")
If Formula1 = vbYes Then Range(selected_cell).Select
Formula2 = ActiveCell
For Each w In Application.Workbooks: w.Activate
If selected_cell < "" Then
If Range("Sheet1!as597") = 4 Then Range(selected_cell).Select
If Formula1 = vbYes Then ActiveCell = Formula2
Else
If Range("Sheet1!as597") = 4 Then Application.Run "M15GoToBotRight"
End If
Next w: ThisWorkbook.Activate
Exit Sub
bob2: MsgBox ("Enter a Column and Row (Ex: z45)")
End Sub



All times are GMT +1. The time now is 09:15 PM.

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