ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   New to Macros (https://www.excelbanter.com/excel-programming/276575-re-new-macros.html)

Greg Wilson[_3_]

New to Macros
 
Don't run this macro on the original data !!! Run it on a
copy until you're sure it does what you want. You cannot
undo macros.

My assumption was that there are headings in Cells A1 and
B1 respectively. The macro will identify the individual
record types, add a new sheet to receive the data, then
copy and paste to the new sheet. It can easily be changed
to run on a subset of selected data instead.

Sub Test()
Dim i As Long, X As Long, RowNum As Long
Dim ThisSht As Worksheet, NewSht As Worksheet

Application.ScreenUpdating = False
RowNum = ActiveSheet.Range("A1").End(xlDown).Row + 1
Set ThisSht = ActiveSheet
X = 0
With ThisSht
For i = 2 To RowNum
If .Cells(i, 1) = .Cells(i - 1, 1) Then
X = X + 1
Else
If i 2 Then
Set NewSht = ThisWorkbook.Sheets.Add
NewSht.Name = .Cells(i - 1, 2)
Range("A1") = .Range("A1")
Range("B1") = .Range("B1")
Range(.Cells(i - X - 1, 1), .Cells(i - 1, 2)).Copy
NewSht.Paste Destination:=Range("A2")
NewSht.Columns("A:B").EntireColumn.AutoFit
X = 0
End If
End If
Next
..Activate
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Regards,
Greg


-----Original Message-----
I am new to Excel macros and need some assistance. I
have a workbook with over 22,000 rows in the first tab. I
would like to create a macro that will create new tabs
and move the contents of the rows at each change in the
value of column A. For example.

Column A Column B
11111 Software
11111 Software 2
11111 Software 3
22222 Wireless
22222 Wireless 2

In this example I would like to move the records (rows)
that have 222222 in column A into a new tab. Any
assistance is appreciated.
.



All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com