ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro avoiding circular reference (https://www.excelbanter.com/excel-worksheet-functions/30561-macro-avoiding-circular-reference.html)

Kanga 85

Macro avoiding circular reference
 
I need a macro that will do the following:
Take the cell highlighed and the next 29 cells in that row,
Subtract the value of A1 from each of these cells and paste the new value
(not the formula) into the same 30 cells,
Do this only once.

Thanks for any help.


R.VENKATARAMAN

suppose Public Sub your data is in C1 to C30
try this sub

public sub test()
Dim cell As Range
For Each cell In Range("c1:c30")
cell = cell - Range("a1")
Next
End Sub
====
perhaps there are more elegant ways.


Kanga 85 wrote in message
...
I need a macro that will do the following:
Take the cell highlighed and the next 29 cells in that row,
Subtract the value of A1 from each of these cells and paste the new value
(not the formula) into the same 30 cells,
Do this only once.

Thanks for any help.




JE McGimpsey

One way:

Public Sub SubtractA1()
Range("A1").Copy
ActiveCell.Resize(1, 30).PasteSpecial _
Paste:=xlValues, _
Operation:=xlSubtract, _
SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
End Sub


In article ,
"Kanga 85" wrote:

I need a macro that will do the following:
Take the cell highlighed and the next 29 cells in that row,
Subtract the value of A1 from each of these cells and paste the new value
(not the formula) into the same 30 cells,
Do this only once.

Thanks for any help.


Kanga 85

Thanks,
This looks simple and repects my active cell.

"JE McGimpsey" wrote:

One way:

Public Sub SubtractA1()
Range("A1").Copy
ActiveCell.Resize(1, 30).PasteSpecial _
Paste:=xlValues, _
Operation:=xlSubtract, _
SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
End Sub


In article ,
"Kanga 85" wrote:

I need a macro that will do the following:
Take the cell highlighed and the next 29 cells in that row,
Subtract the value of A1 from each of these cells and paste the new value
(not the formula) into the same 30 cells,
Do this only once.

Thanks for any help.




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

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