Macro problems

H

Heine

Hi everybody

My formula looks exactly like this:


Sub makeformulae()
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
Formula =
"=if(a9="";"";if(isna(vlookup(a9;råb1;3;false));"";(vlookup(a9;råb1;3;false­))))"

Formula = .Value 'changes to a value if desired
End With
End Sub


As I understand it this should set my defined formula active in all the

cells in column O from row 9 - that is it should return the result of
the formula in the entire column (almost) - but nothing happens. Any
thoughts?


And what can I use this line for?


Formula = .Value 'changes to a value if desired


/Heine
 
B

Bob Phillips

Sub makeformulae()
Dim frng As Range
Const sFormula As String = _
"=if(a9="""";"""";if(isna(vlookup(a9;råb1;3;false));"""";(vlookup(a9;råb1;3;
false))))"
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
.Formula = sFormula
.Value = .Value
End With
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Hi everybody

My formula looks exactly like this:


Sub makeformulae()
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
Formula =
"=if(a9="";"";if(isna(vlookup(a9;råb1;3;false));"";(vlookup(a9;råb1;3;false­
))))"

Formula = .Value 'changes to a value if desired
End With
End Sub


As I understand it this should set my defined formula active in all the

cells in column O from row 9 - that is it should return the result of
the formula in the entire column (almost) - but nothing happens. Any
thoughts?


And what can I use this line for?


Formula = .Value 'changes to a value if desired


/Heine
 
D

Dave Peterson

If Bob's formula didn't work, then I'd try:

Const sFormula As String = _
"=if(a9="""","""",if(isna(vlookup(a9,råb1,3,false)),""""," & _
"(vlookup(a9,råb1,3,false))))"

Semicolons have been replaces with commas--VBA is pretty USA centric.
 
H

Heine

Hi Bob,

thanks for yout input. However this line doesn´t seem to work:

..Formula = sFormula

"Application or object defined error" it says.

Any thoughts?

/Heine
 
D

Dave Peterson

Do you really have a range named: råb1

Hi Bob,

thanks for yout input. However this line doesn´t seem to work:

.Formula = sFormula

"Application or object defined error" it says.

Any thoughts?

/Heine
 
H

Heine

It shouldn´t matter should it? I can always change it to the
traditional way if it´s a problem
 
B

Bob Phillips

It shouldn't be that, the formula should install okay, it would just show an
error in the cell.

Did you notice Dav e's follow-up post to mine where he suggested using
commas in VBA n ot semi-colons. That could throw the application error. Try
it with

Const sFormula As String = _
"=if(a9="""","""",if(isna(vlookup(a9,råb1,3,false))," & _
""""",(vlookup(a9,råb1,3,false))))"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

It shouldn´t matter should it? I can always change it to the
traditional way if it´s a problem
 
H

Heine

So I replace the formula in the below macro with the one you gave me?

What about the line?

.Formula = sFormula



Sub makeformulae()
Dim frng As Range
Const sFormula As String = _
"=if(a9="""";"""";if(isna(vlookup(a9;råb1;3;false));"""";(vlookup(a9;råb1;3­;

false))))"
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
.Formula = sFormula
.Value = .Value
End With
End Sub




Bob said:
It shouldn't be that, the formula should install okay, it would just showan
error in the cell.

Did you notice Dav e's follow-up post to mine where he suggested using
commas in VBA n ot semi-colons. That could throw the application error. Try
it with

Const sFormula As String = _
"=if(a9="""","""",if(isna(vlookup(a9,råb1,3,false))," & _
""""",(vlookup(a9,råb1,3,false))))"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

It shouldn´t matter should it? I can always change it to the
traditional way if it´s a problem
 
H

Heine

It actually works now - thanks guys!
Heine said:
So I replace the formula in the below macro with the one you gave me?

What about the line?

.Formula = sFormula



Sub makeformulae()
Dim frng As Range
Const sFormula As String = _
"=if(a9="""";"""";if(isna(vlookup(a9;råb1;3;false));"""";(vlookup(a9;råb1;3­;

false))))"
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
.Formula = sFormula
.Value = .Value
End With
End Sub
 
B

Bob Phillips

That is only where the error shows, the problem is elsewhere.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

So I replace the formula in the below macro with the one you gave me?

What about the line?

.Formula = sFormula



Sub makeformulae()
Dim frng As Range
Const sFormula As String = _
"=if(a9="""";"""";if(isna(vlookup(a9;råb1;3;false));"""";(vlookup(a9;råb1;3­
;

false))))"
Sheets("Bogholderi").Select
Set frng = Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
With frng
.Formula = sFormula
.Value = .Value
End With
End Sub




Bob said:
It shouldn't be that, the formula should install okay, it would just show an
error in the cell.

Did you notice Dav e's follow-up post to mine where he suggested using
commas in VBA n ot semi-colons. That could throw the application error. Try
it with

Const sFormula As String = _
"=if(a9="""","""",if(isna(vlookup(a9,råb1,3,false))," & _
""""",(vlookup(a9,råb1,3,false))))"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

It shouldn´t matter should it? I can always change it to the
traditional way if it´s a problem


Dave said:
Do you really have a range named: råb1
"=if(a9="""";"""";if(isna(vlookup(a9;råb1;3;false));"""";(vlookup(a9;råb1;3;"=if(a9="";"";if(isna(vlookup(a9;råb1;3;false));"";(vlookup(a9;råb1;3;false­ all
 

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

Top