programaticly filling a cell with a formula

  • Thread starter Thread starter skynugget
  • Start date Start date
S

skynugget

hello all...
i have sheet with 6 columns abcdef.
in colum f (row 2)i have the formula =A2&TEXT(B2,"mmm-yy") i use this
for a refrence in another sheet in the book.

im trying to auto fill cell F with the above formula in a given row
after a value in cell A of the same row is entered. Or i guess it would
be nice for som code to combine 2 cell values and place it in cell F.

can anyone nudge me in the propper direction?

thanks!
 
Why don't we wait until col B is populated? If you already have your formula
in f2 then this will copy it to the row where you entered something in col b

right click sheet tab>view code>insert this>save the workbook.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
Cells(2, "f").Copy Cells(Target.Row, "f")
End Sub
 
Or, without using VBA, just create a formula like =if(LEN(A2&B2)>0;
A2&TEXT(B2,"mmm-yy"); "")

That will keep the cell empty when no text exists in cells A2 & B2 ---
just drag the formula down 50 rows and you're good for 50 lines (or use
more if you like).
 
Don, thanks! This is exactly what i was looking for.... i wanted to
do it this way so i didnt have to copy the formula infanatly down the
shet... thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top