cmschmitz24
Board Regular
- Joined
- Jan 27, 2017
- Messages
- 150
Hello,
Can someone please help with updating an old code.
What the code is trying to do is take values in column B and copy/paste them on a new sheet.
Column B can have multiple lines with different information, but the values in column B will always be the same.
EDIT: What it seems to be having an issue with is pulling data from Column A rather than B to copy/paste and create new sheets.
Can someone please help with updating an old code.
What the code is trying to do is take values in column B and copy/paste them on a new sheet.
Column B can have multiple lines with different information, but the values in column B will always be the same.
Code:
Dim LastCol As Integer, i As Long, iStart As Long, iEnd As Long
Dim ws As Worksheet
Application.ScreenUpdating = False
With ActiveSheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
iStart = 2
For i = 2 To lastrow
If .Range("B" & i).Value <> .Range("B" & i + 1).Value Then
iEnd = i
Sheets.Add after:=Sheets(Sheets.Count)
Set ws = ActiveSheet
On Error Resume Next
ws.Name = .Range("B" & iStart).Value
On Error GoTo 0
ws.Range(Cells(1, 1), Cells(1, LastCol)).Value = .Range(.Cells(1, 1), .Cells(1, LastCol)).Value
.Range(.Cells(iStart, 1), .Cells(iEnd, LastCol)).Copy Destination:=ws.Range("A2")
iStart = iEnd + 1
End If
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
For Each ws In Sheets
Sheets("Retro").Select
Range("A1:R1").Copy
If ws.Visible Then ws.Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Columns("A:R").AutoFit
ActiveSheet.Range("A1").Select
Next
EDIT: What it seems to be having an issue with is pulling data from Column A rather than B to copy/paste and create new sheets.
Last edited by a moderator: