# Help with auto populating cells

#### GodsDsipl

##### New Member
I am creating a materials costing sheet and I need to know how to have excel populate two cells with a number when you put a number in another cell. This is what I was thinking...

if you enter 1 in to cell A! the excel will put the number 6 in A2 and the number 12in A3

=if(A1="1" then A2="6", A3=12) Thanks

### Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

#### Derek

##### Well-known Member
Hi there

You need to put your formula in the cells that will show the answer.
In A2 you need:
=IF(A1=1,6,0)
and in A3 you need:
=IF(A1=1,12,0)

If you do not wish these cells to display 0 when A1 does not contain 1 then you should custom format A2 and A3 as General;;

If you do not want to use formulas, you can trigger this by using an event macro. Go to the VB Editor (right click sheet tab, left click View Code) and paste this code into the large code window:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "\$A\$1" Then Exit Sub
If Target.Address = "\$A\$1" And Target.Value = 1 Then
[a2].Value = 6
[a3].Value = 12
Else
[a2:a3].ClearContents
End If
End Sub

regards
Derek

Replies
3
Views
186
Replies
6
Views
117
Replies
1
Views
53
Replies
1
Views
179
Replies
14
Views
558