Need to use VBA to copy a previous cell and auto fill with increment on the next row

showgun3

New Member
Joined
Apr 1, 2013
Messages
28
Hi, I am new to VBA and macros, is it possible some one can assist me with writing a mini code to copy A1, B1, C1, into next row, but do a selection auto fill meaning increment the numbers, instead of just plain copy and paste.

I have a button on the last row of the table and I also want it to detect the current row, and do an insert first, then do the copy and paste with increment.

Sub InserRow()

With ActiveSheet.Buttons(1) 'Form Control
Range(.TopLeftCell, .BottomRightCell).EntireRow.Select
End With

' Insert blank row.
ActiveCell.EntireRow.Insert shift:=xlDown
'Move up one row.

ActiveCell.Offset(-1, 0).Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False

ActiveCell.Offset(-1, 1).Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
' Selection.AutoFill Destination:=Range(ActiveCell.Offset(0, 0)), Type:=xlFillDefault
' Selection.AutoFill Destination:=ActiveCell.Resize(ActiveCell.Offset(0, -1).Value, 1), Type:=xlFillDefault
Application.CutCopyMode = False

Can anyone help with the selection syntax or if possible with another function, then help please.

Thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Probably a much better way to do this, but for the sake of a speedy solution, try this:

Code:
Option Explicit
Sub InsertIncrement()
Dim rng As Range
Set rng = ActiveCell
rng.Offset(1, 0).EntireRow.Insert shift:=xlShiftDown
rng.Offset(1, 0) = rng + 1
rng.Offset(1, 1) = rng.Offset(0, 1) + 1
rng.Offset(1, 2) = rng.Offset(0, 2) + 1
End Sub
 
Upvote 0
Probably a much better way to do this, but for the sake of a speedy solution, try this:

Code:
Option Explicit
Sub InsertIncrement()
Dim rng As Range
Set rng = ActiveCell
rng.Offset(1, 0).EntireRow.Insert shift:=xlShiftDown
rng.Offset(1, 0) = rng + 1
rng.Offset(1, 1) = rng.Offset(0, 1) + 1
rng.Offset(1, 2) = rng.Offset(0, 2) + 1
End Sub

Thank you, your code works, but I was nt able to utilize it for my purposes. Your Code is not working if the data type is other than numbers.
 
Upvote 0
Well it is a reference number, and the last part is a number, so when you do a copy and drag through excel with mouse, it increments the reference number. It works when you record the macro as well. And it has something to do with below formula but it is stuck at the same cell, I want it to be from the position of the button, which I have from the previous code I posted. The code is working for me, but for my own satisfaction I want it to do copy, paste with increment. Right Now I can only do copy and paste. I figure that is only how I can learn. Thanks again.

Range("C44").Select
Selection.AutoFill Destination:=Range("C44:C45"), Type:=xlFillDefault
Range("C44:C45").Select
 
Upvote 0

Forum statistics

Threads
1,203,727
Messages
6,056,958
Members
444,899
Latest member
Excel_Temp

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