Link to home
Start Free TrialLog in
Avatar of Chaitu235
Chaitu235

asked on

Copy formula using VB code

The formula is there on the H column in the spreadheet.I am pasting data into the spreadsheet from another sheet using macro.We are pasting data from A to G columns.The formula on H will do a vlookup based on value in A column.
Is there a way to automate the formula to all the cells

For example if i pasted data on  A to G in 20 rows .I need the formula on H to be from H1 to H20 automatically.


Please let me know.

Thanks,
Chaitu235
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Is there already a formula in H1? If so then

    Range("H2:H" & Range("G1048576").End(xlUp).Row).Formula = Range("H1").Formula

otherwise

    Range("H1:H" & Range("G1048576").End(xlUp).Row).Formula = "=A1"

where you would change the formula to suit.
Avatar of Chaitu235
Chaitu235

ASKER

Hi Can you please tell me where i should write this code..on worksheet_activate?
I think you got my question wrong...

The code i am looking for is ..

I have formula on H3 column...The data on A through G columns will be results from a query .If query retured 20 rows ..

Data will be there from A3 through  G on 20 rows.   I want the formula on H3 to be copied to next 20 cells on H column.Please help me on that
Can you attach a workbook that has the query results in it?
Martin please find the Spreadsheet attached.Please let me know if you have any questions.
Question_on_Formula.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.