danielphayward
Board Regular
- Joined
- Jan 22, 2016
- Messages
- 69
- Office Version
- 365
- Platform
- Windows
- Web
I'm using Excel 2013 on Windows 7 and while I'm not getting errors, it's also not doing what I want it to, its doing nothing.
What I'm trying to do is go through a list in Column Y and have each row with the same value in Column J copied to a new sheet by the same name.
I can manually copy the code down a bunch of times but the loop function would work perfectly for this...if I could get it to work at all.
If you can help I'd greatly appreciate it.
What I'm trying to do is go through a list in Column Y and have each row with the same value in Column J copied to a new sheet by the same name.
I can manually copy the code down a bunch of times but the loop function would work perfectly for this...if I could get it to work at all.
Code:
Sub CopytoNewSheets()
'
' Macro2 Macro
'
'
Sheets("Input").Select
'I had RowCount as integer but I kept getting Overflow error 6
Dim RowCount As Long
Do Until RowCount = 0
RowCount = Sheets("Open Items").Range("Y2").End(xlDown).Row
'If I exclude the Do Until and Loop function at the end, this code does it what I want it to, maybe its clumsy but I haven't been writing VBA long enough to know.
'Sorts !Input by First Value in Column Y
ActiveSheet.Range("$A$1:$J$3000").AutoFilter Field:=10, Criteria1:=Range("Y2")
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
'Copies Data to new worksheet
Selection.Copy
Sheets(Range("Y2").Value).Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("A1").Select
'Goes back to Open Item worksheet
Sheets("Open Items").Select
Application.CutCopyMode = False
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A1").Select
Sheets("Open Items").Select
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("Open Items").Sort.SortFields.Add KEY:=Range("A1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Open Items").Sort
.SetRange Range("A:J")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlAscending
.Apply
End With
Loop
End Sub
If you can help I'd greatly appreciate it.