Hi, this seems a little bit overkill....
Basically, you would iterate through column B of the source sheet, check if that sheet for each cell in Column B exists, and if not, create it, and rename it. If it does exist, just copy the Row to that other sheet.
Is there anything I am missing here, or will that do? if so, I'll re-arrange it for you.
Regards,
Rob.
Main Topics
Browse All Topics





by: tkeifferPosted on 2007-08-18 at 12:43:52ID: 19723568
Actually, I think I can modify this one. However, if there was a way to do it without specifying individual columns then that would be nice. Does this help?
Sub CreateTabs()
Dim wkbNew As Workbook
Dim shtSrc As Worksheet
Dim shtLoop As Worksheet
Dim shtTarget As Worksheet
Dim intRowSrc As Integer
Dim intRowTrgt As Integer
Set shtSrc = ActiveSheet
Set wkbNew = Workbooks.Add()
With wkbNew
'This rowSrc = 5 thing is where it looks for the blank row
intRowSrc = 5
Do While shtSrc.Cells(intRowSrc, 5) <> ""
'Find sheet
Set shtTarget = Nothing
For Each shtLoop In .Sheets
If shtLoop.Name = shtSrc.Cells(intRowSrc, 5) Then
Set shtTarget = shtLoop
Exit For
End If
Next shtLoop
'Create and setup sheet if not exist
If shtTarget Is Nothing Then
Set shtTarget = .Sheets.Add()
With shtTarget
.Name = shtSrc.Cells(intRowSrc, 5)
.Cells(1, 1) = "Knowledge Category 1"
.Cells(1, 2) = "Knowledge Category 2"
.Cells(1, 3) = "Solution ID"
.Cells(1, 4) = "Solution Summary"
.Cells(2, 1).Select
End With
End If
'Enter new line
With shtTarget
'Find next blank row
intRowTrgt = 1
Do
intRowTrgt = intRowTrgt + 1
Loop Until .Cells(intRowTrgt, 1) = ""
'Enter data
.Cells(intRowTrgt, 1) = shtSrc.Cells(intRowSrc, 5)
.Cells(intRowTrgt, 2) = shtSrc.Cells(intRowSrc, 6)
.Cells(intRowTrgt, 3) = shtSrc.Cells(intRowSrc, 16)
.Cells(intRowTrgt, 4) = shtSrc.Cells(intRowSrc, 19)
End With
intRowSrc = intRowSrc + 1
Loop
'Delete Sheets 1 to 3
For Each shtTarget In .Sheets
Select Case shtTarget.Name
Case "Sheet1", "Sheet2", "Sheet3"
shtTarget.Delete
End Select
Next shtTarget
End With