I have a small table and some code which shouls extract the Generic Category value for each row and then use that Name value to greate new worksheets with.
My table:
and my code:
So my question are how do I fix this line cWs.Name = Format(cProduct.Value.Offset(, 1)) 'this is where im getting error
and is this the best way to loop through 100k rows?
My table:
and my code:
VBA Code:
Sub CommandButton1_Click()
Dim cProduct As String
Dim myRange As Range
Dim sCell As Range
Dim copySize As Long
Dim colCount As Integer
Dim lCount As Integer
Set myRange = Range("A3").CurrentRegion
cProduct = myRange.Cells(1, 1)
Set sCell = myRange.Cells(1, 1)
colCount = myRange.Columns.Count
Dim dWs As Worksheet, cWs As Worksheet, cfRange As Range
Set dWs = ActiveSheet
lCount = 1
'deleteSheets
Do While Len(cProduct) > 1
dWs.Activate
copySize = Range(sCell, sCell.End(xlDown)).Rows.Count
Range(sCell, sCell.Offset(copySize - 1).Offset(, colCount - 1)).Copy
Set cWs = Sheets.Add
cWs.Range("A3").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
'code for autofitting columns
cWs.Columns("C:P").EntireColumn.AutoFit
cWs.Name = Format(cProduct.Value.Offset(, 1)) 'this is where im getting error
lCount = lCount + 1
Set sCell = sCell.Offset(copySize + 1)
cProduct = sCell.Value
Loop
End Sub
So my question are how do I fix this line cWs.Name = Format(cProduct.Value.Offset(, 1)) 'this is where im getting error
and is this the best way to loop through 100k rows?