storemannequin
Board Regular
- Joined
- May 29, 2010
- Messages
- 108
I'm trying to save this new workbook to the original workbooks filepath location but when I run the code I get an alert saying that there is already a file of the same name/path saved in my folder and asks would you like to replace - which when I click yes, nothing happens. I'm guessing something is wrong with the code here because I checked before running the macro if there was the same filename I deleted. I hightlighted in red the part not working.
Rich (BB code):
Sub FDD()
Dim WBO As Workbook, WBD As Workbook
Dim WSO As Worksheet, WSD As Worksheet
Dim i As Long, FR As Long, FC As Long
FR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
FC = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set WBO = ActiveWorkbook
Set WSO = ActiveSheet
Set WBD = Workbooks.Add(template:=xlWBATWorksheet)
Set WSD = WBD.Worksheets(1)
Application.ScreenUpdating = False
WSO.Range("A1").CurrentRegion.Rows(1).Copy Destination:=WSD.Range("A1")
WSD.Name = "Danaher Master"
nextrow = 2
For i = FR To 2 Step -1
If StrComp(CStr(WSO.Cells(i, 2)), "DEXIS ") = 0 Then
WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
WSO.Rows(i).EntireRow.Delete
nextrow = nextrow + 1
ElseIf StrComp(CStr(WSO.Cells(i, 2)), "GENDEX") = 0 Then
WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
WSO.Rows(i).EntireRow.Delete
nextrow = nextrow + 1
ElseIf StrComp(CStr(WSO.Cells(i, 2)), "KAVO ") = 0 Then
WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
WSO.Rows(i).EntireRow.Delete
nextrow = nextrow + 1
ElseIf StrComp(CStr(WSO.Cells(i, 2)), "P&C ") = 0 Then
WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
WSO.Rows(i).EntireRow.Delete
nextrow = nextrow + 1
ElseIf StrComp(CStr(WSO.Cells(i, 2)), "IMGSCI") = 0 Then
WSO.Cells(i, 1).Resize(, FC).Copy Destination:=WSD.Cells(nextrow, 1)
WSO.Rows(i).EntireRow.Delete
nextrow = nextrow + 1
End If
FN = "this" & ".xlsx"
FP = WBO.Path & Application.PathSeparator
WBD.SaveAs Filename:=FP & FN
Next i
End Sub