How can I retain data from a formula?

PaddyG

New Member
Joined
Nov 4, 2008
Messages
18
I need a solution so that each day I can get a value from a single cell but it appears in a new column each day.

eg, A1 contains a numerical value (based on a formula)
Each day there is a new column, say, Monday = B1, Tuesday = C1 etc.
On Monday B1 takes the value of A1 and 'freezes' the value in B1
On Tuesday C1 takes the value of A1 and 'freezes' the value in C1, but the value in B1 remains as it was when it was originally frozen.

Any help on this would be greatly appreciated!!
 

Some videos you may like

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.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Something like this perhaps

Code:
Sub test()
Dim LC As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
With Cells(1, LC)
    .Copy Destination:=.Offset(, 1)
    .Value = .Value
End With
End Sub
 

PaddyG

New Member
Joined
Nov 4, 2008
Messages
18
Wow- nearly there with this one....it's saving the data and moving along one cell to the right each time, but it's taking the value from the previous cell on the left, whereas I need it to always take the value of A1.

It's probably something very easy to do, but I'm not very good at this....

I'd be grateful for a more of your assistance.

Thanks!
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Perhaps this

Code:
Sub test()
Dim LC As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
With Cells(1, LC)
    Cells(1, 1).Copy Destination:=.Offset(, 1)
    .Value = .Value
End With
End Sub
 

PaddyG

New Member
Joined
Nov 4, 2008
Messages
18

ADVERTISEMENT

It's returning a value of '0' - I think this is because A1 is referencing another cell to get it's value (ie, A1 "=A7"). However, when I remove the formula and directly type the value into A1 it does work.

Sorry to be a pain!
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
This seems to work

Code:
Sub test()
Dim LC As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
With Cells(1, LC)
    .Offset(, 1).Formula = Cells(1, 1).Formula
    .Value = .Value
End With
End Sub
 

PaddyG

New Member
Joined
Nov 4, 2008
Messages
18

ADVERTISEMENT

Brilliant!!

One final question - how can i amend it so that it pulls the value from a different cell eg B6?

Thanks for all your help!
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()
Dim LC As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
With Cells(1, LC)
    .Offset(, 1).Formula = Cells(6, 2).Formula
    .Value = .Value
End With
End Sub
 

PaddyG

New Member
Joined
Nov 4, 2008
Messages
18
Playing with this a bit more - is there any way I can put multiple instances of this in one macro, eg, run the macro and it updates many cells pulling value from many sources.

Ideally I'd like the macro to run once and update multiple cells, rather than having a macro for each cell (row)?

Thanks again!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,151
Messages
5,623,048
Members
415,948
Latest member
swart430

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
Top