Ok, I have a doozy here. Or, at least, I think it is complicated!
First, I have a macro that combines multiple workbooks from a folder on my desktop into a new single workbook. This works perfectly.
Second, I have a macro that names each sheet based on the value in cell A2. This works perfectly.
Here is my problem ... I thought that the value in cell A2 of each of my sheets was consistent down the column. It is not. Column A in all of my sheets contain Project numbers. I need one sheet per project number. Some sheets have only one project number, but others have multiple project numbers.
Is it possible, with code, that the sheets with multiple project numbers can be split into multiple sheets, and the sheets that already only have one project code can be ignored? Also, each sheet has a header row, so that would also need to carry over to new sheets.
If it is possible to do what I want, then I would need to run my macro for renaming all of the sheets afterward.
I have almost everything else figured out for this project!!
Thank you!
.
.
PS. The number of columns can vary from one sheet to another. That is why I do not try to load all of the original workbooks into a single sheet of a new workbook, and then split them out. That would be too easy!
PPS. Just to share, I do already have some code that splits one sheet into multiple sheets based on values in cells, but it works if starting with a single sheet, not multiple like in my request above. Anyway, I just thought I'd share that code in case it might give some value back to somebody:
Sub Joyce()
Dim lr As Long
Dim ws As Worksheet
Dim vcol, I As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
vcol = 11
Set ws = Sheets("NOH402 - All Results-SI")
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = "A1:P1"
titlerow = ws.Range(title).Cells(1).Row
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
For I = 2 To lr
On Error Resume Next
If ws.Cells(I, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(I, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(I, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For I = 2 To UBound(myarr)
ws.Range(title).AutoFilter Field:=vcol, Criteria1:=myarr(I) & ""
If Not Evaluate("=ISREF('" & myarr(I) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(I) & ""
Else
Sheets(myarr(I) & "").Move after:=Worksheets(Worksheets.Count)
End If
ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(I) & "").Range("A1")
Sheets(myarr(I) & "").Columns.AutoFit
Next
ws.AutoFilterMode = False
ws.Activate
Did not want to, but I am desperate: I sort of cross-posted at https://chandoo.org/forum/threads/sp...ontents.41060/ It's not exactly a cross-post, so I don't even know if I need to inform of it here, but I don't want my wrist slapped. Why is cross-posting even a problem? In life, don't we use all resources available to us? Seems silly, but whatever ... I want to be compliant.
Bookmarks