I need a formula in one cell to put data in a different cell.

GreasySpot

New Member
Joined
Feb 1, 2013
Messages
48
I need a formula in one cell to put data in a different cell.
example:

a1 value is 1000
a2 value is empty

I want a formula in a3 to read the value of a2. If it has a value then do nothing. If it is empty then make the value of a2=a1.

Simple right?
 
Because you are manipulating values in A2 you cannot use a formula to do this. You will need to use a VBA solution.

If you want the values to appear in A3, then you could use this formula

=if(A2<>"",A2, A1). This would appear in A3

Your VBA solution would be as follows

Code:
Option Explicit


Sub foo()


If IsNull(Range("A2")) Then
Range("A2").Value = Range("A1").Value
End If


End Sub
 
Upvote 0
I need a formula in one cell to put data in a different cell.
example:

a1 value is 1000
a2 value is empty

I want a formula in a3 to read the value of a2. If it has a value then do nothing. If it is empty then make the value of a2=a1.

Simple right?

You need to explain clearly what you want.
 
Upvote 0
Because you are manipulating values in A2 you cannot use a formula to do this. You will need to use a VBA solution.

If you want the values to appear in A3, then you could use this formula

=if(A2<>"",A2, A1). This would appear in A3

Your VBA solution would be as follows

Code:
Option Explicit


Sub foo()


If IsNull(Range("A2")) Then
Range("A2").Value = Range("A1").Value
End If


End Sub

This looks good alan. Thanks.

My excel file has 7 sheets, 1 for each day of the week. On each sheet I have 2 cells where I need this code to apply. Does this code need to be specific for each instance or sheet?

Thanks again,
 
Upvote 0
You can open each sheet and run the code or you can use the following to run it once and it will update all seven sheets.


Code:
Option Explicit
Sub foo()
Dim ws as worksheet
For each ws in worksheets
If IsNull(Range("A2")) Then
Range("A2").Value = Range("A1").Value
End If
Next ws
End sub
 
Upvote 0
I got to looking harder at my workbook and realized I don't need to process every sheet just: Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.

Thank you in advance for ALL your help.
 
Upvote 0

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