Excel Macro - Set and Autofill a range?
Solved/Closed
Related:
- Selection.insert shift:=xltoright
- Spell number in excel without macro - Guide
- Excel mod apk for pc - Download - Spreadsheets
- How to set auto redial on android - Guide
- Excel marksheet - Guide
- Kernel for excel - Download - Backup and recovery
2 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Apr 26, 2012 at 10:04 AM
Apr 26, 2012 at 10:04 AM
Hi Joe G,
So basicly you would like to shift Column A to the right to become Column B.
Cel A1 should contain the text "Index" and below A1 a counter should start from 1 until the last used cell from column B.
Try out the following code:
Best regards,
Trowa
So basicly you would like to shift Column A to the right to become Column B.
Cel A1 should contain the text "Index" and below A1 a counter should start from 1 until the last used cell from column B.
Try out the following code:
Sub test() Dim lRow As Long Columns("A:A").Select Selection.Insert Shift:=xlToRight Range("A1").Value = "Index" Range("A2").Value = 1 Range("A3").Value = 2 Range("A2:A3").Select lRow = Range("B" & Rows.Count).End(xlUp).Row Selection.AutoFill Destination:=Range("A2:A" & lRow) End Sub
Best regards,
Trowa
Trowa,
Thank you for the prompt response and help with this code. The code worked perfectly, however a new problem arose. Basically, after running the autofill function, the macro is supposed to select/copy B:B and then paste the formatting to A:A. Below is the section of code I am having a problem with. Could you please see what can be done to correct this error (from Columns("B:B") to end)?
Thank you in advance for your help!
Joe G.
Thank you for the prompt response and help with this code. The code worked perfectly, however a new problem arose. Basically, after running the autofill function, the macro is supposed to select/copy B:B and then paste the formatting to A:A. Below is the section of code I am having a problem with. Could you please see what can be done to correct this error (from Columns("B:B") to end)?
Dim lRow As Long Columns("A:A").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("A1").Value = "Index" Range("A2").Value = 1 Range("A3").Value = 2 Range("A2:A3").Select lRow = Range("B" & Rows.Count).End(xlUp).Row Selection.AutoFill Destination:=Range("A2:A" & lRow) Columns("B:B").Select Selection.Copy Columns("A:A").Select Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False
Thank you in advance for your help!
Joe G.