Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

macro

0

nsh.Cells(148, 5).Formula = Int(settings.Range("G" & i) * nsh.Cells(146, 5).Value)

the code give an hardcoded output, how to get the formula the in the cell.

Answer
Discuss

Answers

0

Hi Chirag and welcome to the Forum.

First, please edit your question title to something like "Applying a formula using VBA"- that would be far more helpful to others than the somewhat meaningless, generic "macro". Secondly, please delete the duplicate question with the title "macro" (if Don hasn't already).

You have to write the formula as a string, starting with "=" and building up the parts (as if you were writing it in a worksheet).

In your case the line should read:

nsh.Cells(148, 5).Formula = "=Int(" & settings.Name & "!G" & i & "*" & nsh.Cells(146, 5).Address & ")"

Hope this helps.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login