Hi there!
This is going to be my first post and probably the first macros-enabled excel sheet created by me, so I hope for your help!
So I'm trying to do the following:
The sheet consists of 13 columns.
I want to protect it and then send to my colleagues. The main feature of it would be 2 buttons to insert the rows. The first button would insert all 13 columns below selected cell in a row and copy all formatting. Also cell g contains the formula which I'd like to be filled down (NOT COPIED, like I saw many times in the answers). So basically this is a recorded macro of what I'm trying to do:
The second button would do the following: it will insert the row below selected cell and merge cells from A to J with the cells from above rows (not all together, I need A72 to be merged with A 71, then B72 with B71, etc). Then two cells K and L would be just inserted and again cell M would be merged with above cell (like M2 with M1)![]()
Sub Macro1() ' ' Macro1 Macro ' ' Keyboard Shortcut: Ctrl+i ' Rows("72:72").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("G71").Select Selection.AutoFill Destination:=Range("G71:G72"), Type:=xlFillDefault Range("G71:G72").Select End Sub
So below is the VBA code that I want to be done by just clicking the button:
L&G, if somebody would help me with that I would probably be one of the happiest men in the world.![]()
Sub Macro2() ' ' Macro2 Macro ' ' Keyboard Shortcut: Ctrl+s ' Rows("71:71").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("A71:A72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("B71:B72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("C71:C72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("D71:D72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("E71:E72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("F71:F72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("G71:G72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("H71:H72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("I71:I72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("J71:J72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("M71:M72").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge End Sub
I'm also attaching the sheet so you understand what I want exactly.
sample.xlsm
And to make me happy for the rest of my life - can you tell me how can I hide all columns starting from AA to the end and rows starting from 50?
Bookmarks