VBA to paste data into specified number of columns

jonny1984

New Member
Joined
Apr 27, 2012
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
Hi

I currently have VBA code to copy a formula (from cell H5) and then paste it into a big table which then runs calculations.

The formula in H5 is quite long (has several "VLOOKUPS" etc so when its pasted and calculates it can take a long time

To speed up the process I wondered if its possible to adapt my VBA script to it only pastes into rows / columns that are required - I could easily put the maximum number of rows (currently 43) and maximum number of columns (currently 25) into a cell .. for example I could add in cell A1 = 43, and cell A2 = 25 (and I am fine writing a formula which will automaticlaly update those cells as necessary)

How should I update the VBA script below so it only pastes the formula from "H5" into a range that is 43 rows down (ref cell A1) and 25 (ref cell A2) columns across - ie where the 43 and 25 will be dependent on the formula result in Cells A1 and A2 ?

THnaks in advance !!!!

Sheets("Sheet1").Range("H5").Copy
Sheets("Sheet1").Range("H5:EZ9999").PasteSpecial Paste:=xlPasteFormulas
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Try this
VBA Code:
With Sheets("Sheet1")
  .Range("H5").Copy
  .Range("H5").Resize(.Range("A1").Value, .Range("A2").Value).PasteSpecial Paste:=xlPasteFormulas
End With
 
Upvote 0
Amazing - this worked ! Perfectly

Thank you so much, you are a genius!!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

.. and for updating your profile. (y)
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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