New to Editing VBA

Andrew_UK

Board Regular
Joined
Jun 3, 2015
Messages
53
Hi All,

I'm moderately experienced with recording simple macros in Excel. I've now been asked to build a far more complex Macro and I've got it working (mostly). I'm now at a point where I would like to tweak/improve the code for the purposes of making it easier to read - thing is I'm still very new to understanding the various tricks in VBA code writing.

So that it looks neater I'd like a particular set of formulae which are pre-set in cells G2 and H2 to autofill to the last Row in the spreadsheet (which will definitely be the last cell in columns A:B, and possibly the last cell in columns C:F as well). I tried recording this and it gives me this as part of the code:

Range("G2:H2").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("G2:H35414")

Fortunately this is the maximum range that could be required for the foreseeable future, but if the resulting report only covers 200 lines then I'd rather these formulae did also.

Rather than 'just' getting an answer I'd be really keen to learn how the formula you provide works. Thanks in advance for your help.

Best Regards,

Andrew_UK
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Code:
lastrow = Columns("A:B").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("G2:H2").AutoFill Destination:=Range("G2:H" & lastrow)

lastrow is found by searching from the bottom of columns A & B for a cell with a value or formula in it, and assigns the row no.
 
Upvote 0

Forum statistics

Threads
1,206,826
Messages
6,075,092
Members
446,119
Latest member
BrianAndrews

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