Array formula problem in VB

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,

I'm trying to make a spreadsheet wherby formulas are automatically
entered in column A, dependent on data being in column B.

Brad helped me out with the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
If IsEmpty(Target.Value) Then
Target.Offset(0, -1).Clear
Else: Target.Offset(0, -1).Formula = "=(b1*2)"
End If
End If
End Sub

This works like a charm, but I fogot to mention in my original post
that I would like the formula entered to be: b1 in a1, b2 in
a2,...,b99 in a99 , possibly an array formula.

Any help would be greatly appreciated.

Paul
 
Hi
try replacing the line
Else: Target.Offset(0, -1).Formula = "=(b1*2)"
with
Else: Target.Offset(0, -1).FormulaR1C1="=R[0]C[1]*2"
 
At the risk of pushing my luck..

The below formlua works great:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
If IsEmpty(Target.Value) Then
Target.Offset(0, -1).Clear
Else: Target.Offset(0, -1).FormulaR1C1 = "=R[0]C[1]*2"
End If
End If
End Sub

But can i be so bold as to ask what syntax i could use if my target
column is on another worksheet (i.e. sheet2 column b).

Paul
 
Hi Paul
not quite what formula you want but you may try
Target.Offset(0, -1).FormulaR1C1 = "='sheet2'!R[0]C[1]*2"
 
Thanks for the responses today to Frank.

That will evaluate the values based on the values in the second sheet
fine, but won't clear the formulas as the values in the second sheet are
empty.

I think i need the

If Target.Column = 2

line to refer to the column in the second sheet...ie

if target.column ='sheet2!'2 kindof thing....


god i'm crap at excel, i think i'll leave it...i'm going mad.
 
Hi
try
Target.Offset(0, -1).FormulaR1C1 =
"=IF('sheet2'!R[0]C[1]<>"""",'sheet2'!R[0]C[1]*2,"""")"
 

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