VBA adding formulas referencing to new sheet

telpek

New Member
Joined
Sep 5, 2017
Messages
6
Hi all,

I have a code which adds two new sheets ws2 and ws3 by the following script

Dim ws2 As Worksheet: Set ws2 = Sheets.Add

and it works fine.

I wrote a macro which adds all sort of formulas in both ws2 and ws3

But when I wanted to add formula to ws3 looking up values in ws2, the macro was unable to find the sheet ws2. I tried putting brackets around ws2 in the below code too, but the macro would not just locate ws2.

With ws3.Range("E4:E" & LastRow)
.Formula = "=VLOOKUP(A4,ws2!A:C,3,FALSE)"
End With

Please advise!

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Njimack, could you please help me with a similar problem. The macro just does not like my formula

With ws3.Range("F4:F" & LastRow3)
.Formula = "=SUMIF(" & ws2.Name & " ! G:G, A:A ," & ws2.Name & " !H:H)"
End With

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top