Autofill Macros

Maryna

New Member
Joined
Dec 3, 2019
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi, I have the following code that is not working like I want it to. When the active cell is before column Q then columns A2-C2 copy and fill in columns R-T. If the active cell is after Q then cells A2-Q2 copy and fill down in column S to AH. What I want is from A2 to Q2 to fill down to the last row in the table. Any tips on how to better my code? The macros needs to work on several workbooks each with their own table but the column names are the same in each table.

Sub Macro3_Autofill()
'Fills down to last row in table

Dim LastRow As Range
Dim Selection1 As Range
Dim Selection2 As Range

Set LastRow = ActiveSheet.UsedRange.SpecialCells(xlLastCell)
Set Selection1 = ActiveSheet.Range("A2:Q2")
Set Selection2 = ActiveSheet.Range("A2:Q2", LastRow)
Selection1.AutoFill Destination:=Selection2, Type:=xlFillDefault

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I have the following code that works(recorded macros):

Range("D2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Range("R3").Select
Application.CutCopyMode = False
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Range("S2").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Range("R2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0%"
Range("R2").Select
Selection.Style = "Percent"

Is this the most practical solution for a fill down macros?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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