using ROW() in VBA

Asked

Viewed 74 times

0

Good afternoon,

I want to multiply the value of the fourth cell on the left by the line number but there is an error when using Worksheetfunction.Row(RC[-4]) someone can help??

Range("H2").Select
ActiveCell.FormulaR1C1 = "=RC[-4]* WorksheetFunction.Row(RC[-4])"
Range("H2").Select
Selection.AutoFill Destination:=Range("H2", "H" & linha)
Range("H2", "H" & linha).Select

1 answer

0

When using .FormulaR1C1 a formula is inserted in Excel. Then the VBA function WorksheetFunction cannot be used within an Excel function.

Follow the code to get around the problem:

Range("H2").Select
ActiveCell.FormulaR1C1 = "=RC[-4]*Row(RC[-4])"
Range("H2").Select
Selection.AutoFill Destination:=Range("H2", "H" & linha)
Range("H2", "H" & linha).Select

Obs.: .Select/. Activate/. Activecell should be avoided almost always (except to activate events or other occasions that is possible only with Select).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.