Drag/fill colums and Delete Columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know I can drag/fill and delte a colum range as follows below from a
recorded macro. How do I use column numbers in VBA to replicate these acts?
Assume ahead of time I know for the drag/fill I kno my range is C2:C17.
Also assume that for the delete I know the starting range of C19:J32.

Thanks

'Drag and fill
Range("C2:C17").Select
Selection.AutoFill Destination:=Range("C2:J17"), Type:=xlFillDefault
Range("C2:J17").Select

'Delete Range
Range("C19:J32").Select
Range("J19").Activate
Selection.ClearContents
 
ExcelMonkey said:
I know I can drag/fill and delte a colum range as follows below from a
recorded macro. How do I use column numbers in VBA to replicate these
acts?
Assume ahead of time I know for the drag/fill I kno my range is
C2:C17.
Also assume that for the delete I know the starting range of C19:J32.

Thanks

'Drag and fill
Range("C2:C17").Select
Selection.AutoFill Destination:=Range("C2:J17"), Type:=xlFillDefault
Range("C2:J17").Select

'Delete Range
Range("C19:J32").Select
Range("J19").Activate
Selection.ClearContents

could be..
Range("C19:J32").Select
Selection.ClearContents
Range("C19").Select


the auto fill could be this

Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C17"),
Type:=xlFillDefault
Range("D2").Select
 
Sub fillcol()
Cells(2, 3).AutoFill Destination:=Range(Cells(2, 3), Cells(17, 3))
End Sub

for the active column
Sub fillcol()
ac=activecell.column
Cells(2, ac).AutoFill Destination:=Range(Cells(2,ac), Cells(17, ac))
End Sub

same idea for your delete
Range(Cells(2,3), Cells(17, 13)).clear
 
So Don why is this not working: I am trying to fill range C3:C17 to F3:F17.

Sub fillcol()
Dim X As Integer


Range(Cells(3, 3), Cells(17, 3)).Select
Selection.AutoFill Destination:=Range(Cells(3, 6), Cells(17, 6))
End Sub
 
I think? this is what you want.
You will notice that I also removed the selections. Learn to NOT select
unless necessary.

Sub fillcol()
Range(Cells(3, 3), Cells(17, 3)). _
AutoFill Destination:=Range(Cells(3, 3), Cells(17, 6))
'you had
'________________Range(Cells(3, 6), Cells(17, 6))

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top