I have this handy little piece of code that someone helped me create and now that I have modified the spreadsheet the code no longer works as expected; with the proper adjustments of course.
In the change of the spreadsheet I merely added 4 columns and moved the critera range. The span of the parts to be copied changed from 22 to 26 and the criteria range was formerly A5
35.
The problem lies within the catching of all the companies, for example DIS. When running the code the code will find the row with the DIS copy it and paste it into the proper sheet; however it does not go back and check for either another DIS or any of the other companies. I am not very good with VBA so go easy on me if its somthing really simple or lame.
Thanks
tW33k.
This is my adjusted code.
Old Code that works
In the change of the spreadsheet I merely added 4 columns and moved the critera range. The span of the parts to be copied changed from 22 to 26 and the criteria range was formerly A5
The problem lies within the catching of all the companies, for example DIS. When running the code the code will find the row with the DIS copy it and paste it into the proper sheet; however it does not go back and check for either another DIS or any of the other companies. I am not very good with VBA so go easy on me if its somthing really simple or lame.
Thanks
tW33k.
This is my adjusted code.
Code:
Public Sub ParseAllClientsList()
Application.ScreenUpdating = False
Dim DoCopy As Boolean
CriteriaRange = "D5:D36"
If Not SheetExists("All Clients") Then Exit Sub
With Sheets("All Clients")
For Each company In .Range(CriteriaRange)
DoCopy = True
Select Case Trim(UCase(company.Text))
Case "IND": TargSh = "Independent"
Case "UNI": TargSh = "Universal"
Case "MSFT": TargSh = "Microsoft"
Case "PAR": TargSh = "Paramount"
Case "DWS": TargSh = "Dreamworks"
Case "DIS": TargSh = "Disney"
Case "VEN": TargSh = "Ventura"
Case "PP": TargSh = "PreProduction"
Case "FOX": TargSh = "Fox"
Case Else
DoCopy = False
If Len(company.Text) > 0 Then
msg = "There is no sheet specified for : " & Chr(34) & company & Chr(34) & " ."
pt = MsgBox(msg, vbCritical, "Record not transfered")
End If
End Select
If DoCopy Then
If SheetExists(TargSh) Then
company.EntireRow.Copy
With Sheets(TargSh)
NxRow = .Cells(26, 1).End(xlUp).Row + 1
.Paste Destination:=.Range("A" & "5")
End With
End If 'do copy
End If 'sheet exists
Next company
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Private Function SheetExists(sname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then
SheetExists = True
Else
SheetExists = False
msg = "The sheet : " & Chr(34) & sname & Chr(34) & " does not exist ."
pt = MsgBox(msg, vbCritical, "Record not transfered")
End If
End Function
Old Code that works
Code:
Public Sub ParseAllClientsList()
Application.ScreenUpdating = False
Dim DoCopy As Boolean
CriteriaRange = "A5:A35"
If Not SheetExists("All Clients") Then Exit Sub
With Sheets("All Clients")
For Each company In .Range(CriteriaRange)
DoCopy = True
Select Case Trim(UCase(company.Text))
Case "IND": TargSh = "Independent"
Case "UNI": TargSh = "Universal"
Case "MSFT": TargSh = "Microsoft"
Case "PAR": TargSh = "Paramount"
Case "DWS": TargSh = "Dreamworks"
Case "DIS": TargSh = "Disney"
Case "LG": TargSh = "LionsGate"
Case "PP": TargSh = "PreProduction"
Case Else
DoCopy = False
If Len(company.Text) > 0 Then
msg = "There is no sheet specified for : " & Chr(34) & company & Chr(34) & " ."
pt = MsgBox(msg, vbCritical, "Record not transfered")
End If
End Select
If DoCopy Then
If SheetExists(TargSh) Then
company.EntireRow.Copy
With Sheets(TargSh)
NxRow = .Cells(22, 1).End(xlUp).Row + 1
.Paste Destination:=.Range("A" & NxRow)
End With
End If 'do copy
End If 'sheet exists
Next company
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Private Function SheetExists(sname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then
SheetExists = True
Else
SheetExists = False
msg = "The sheet : " & Chr(34) & sname & Chr(34) & " does not exist ."
pt = MsgBox(msg, vbCritical, "Record not transfered")
End If
End Function