Hello, I am trying to use the vba code below to copy and paste simmilar data from a very large excel sheet where column A has unique identifiers and this is how I would like to seprate my different excel sheets that will be created with the vba code. But i get stuck on "Set stName = Sheets(idName)" at this part of the code and get the error message run-time error '9': subscript out of range. Please help!
Sub SplitToSheets()
Dim stOrig As Worksheet
Dim stName As Worksheet
Dim idName As Variant
Dim lnCont As Long
Dim idCont As Long
Application.ScreenUpdating = False
lnCont = 0
idCont = 0
Set stOrig = Sheets("Sheet1") 'replace sheet1 with your sheet name
lnCont = Application.CountA(stOrig.Columns(1))
For i = 2 To lnCont
idName = stOrig.Cells(i, 1) 'replace 2 with the column that the ID is in
Set stName = Sheets(idName)
idCont = Application.CountA(stName.Columns(1))
stOrig.Rows(i).Copy Destination:=stName.Rows(idCont)
idName = ""
idCont = 2
Set stName = Nothing
Next i
Application.ScreenUpdating = True
Set stOrig = Nothing
End Sub
Sub SplitToSheets()
Dim stOrig As Worksheet
Dim stName As Worksheet
Dim idName As Variant
Dim lnCont As Long
Dim idCont As Long
Application.ScreenUpdating = False
lnCont = 0
idCont = 0
Set stOrig = Sheets("Sheet1") 'replace sheet1 with your sheet name
lnCont = Application.CountA(stOrig.Columns(1))
For i = 2 To lnCont
idName = stOrig.Cells(i, 1) 'replace 2 with the column that the ID is in
Set stName = Sheets(idName)
idCont = Application.CountA(stName.Columns(1))
stOrig.Rows(i).Copy Destination:=stName.Rows(idCont)
idName = ""
idCont = 2
Set stName = Nothing
Next i
Application.ScreenUpdating = True
Set stOrig = Nothing
End Sub