# Using a module when recording a macro



## Ghais Chatila (Dec 6, 2022)

Hello,

i am recording a macro that rearranges some cells, then i want it to add a blank row after each distinct entry in the first column (SEE BELOW EXAMPLE)






I found below code to add blank row. How can i integrate this code into a macro that i will record, or after recording it.






						How to insert blank rows when value changes in Excel?
					






					www.extendoffice.com


----------



## rollis13 (Dec 6, 2022)

Just before the `End Sub` of your recorded macro add: `Call InsertRowsAtValueChange`


----------



## Ghais Chatila (Dec 6, 2022)

Thanks @rollis13 
not sure if i did correctly. here is what happened.


----------



## rollis13 (Dec 6, 2022)

Where did you paste the macro you showed in post #1 ? It goes in a Standard module.


----------



## Ghais Chatila (Dec 6, 2022)

rollis13 said:


> Where did you paste the macro you showed in post #1 ? It goes in a Standard module.


i don't know how to integrate it in my macro. Also that module in post #1 will ask me at one point to select the range of cells to apply this operation...


----------



## rollis13 (Dec 6, 2022)

Cut/paste the macro you showed in post #1 from where it is now located to below the macro you showed in post #3 and launch this second macro.


----------



## Ghais Chatila (Dec 7, 2022)

Thank you !!


----------



## Ghais Chatila (Dec 30, 2022)

Hello

i am not sure why this is still giving me an error... when i run the macro, i get an error and the cursor is highlighted where i put a bunch of stars. Please help 

Sub AC_tab_Matchup()
'
' AC_tab_Matchup Macro
'

'
    ActiveCell.Range("A1:A32").Select
    Selection.Cut
    ActiveCell.Offset(0, -1).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(0, 11).Range("A1:A32").Select
    Selection.Cut
    ActiveCell.Offset(0, -10).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(0, 12).Range("A1:A32").Select
    Selection.Cut
    ActiveCell.Offset(0, -10).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(0, 1).Range("A1:I32").Select
    Selection.Delete Shift:=xlToLeft
    ActiveCell.Offset(1, -3).Range("A1:A31").Select
    Selection.NumberFormat = "m/dd/yy;@"
    ActiveCell.Offset(0, 2).Range("A1:A31").Select
    Selection.NumberFormat = "m/dd/yy;@"
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveCell.Offset(-1, -6).Range("A1:G32").Select
    ActiveWorkbook.Worksheets("AC").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("AC").Sort.SortFields.Add2 Key:=ActiveCell.Range( _
        "A1:A31"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("AC").Sort
        .SetRange ActiveCell.Offset(-1, 0).Range("A1:G32")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
*************        
    Sub InsertRowsAtValueChange()
'Update by Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 2 Step -1
    If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
        WorkRng.Cells(i, 1).EntireRow.Insert
    End If
Next
Application.ScreenUpdating = True
End Sub


----------



## rollis13 (Dec 30, 2022)

This a completly different problem and topic so you should open a new thread for this.
Anyway, there are two macros in the code you posted and the first has at least a missing `End Sub` as your editor clearly informs you.


----------

