
Hi All, I'm working with the following code:
Sub Export()
Dim fName As String, fPath As String
Dim PartsLR As Long
PartsLR = Sheets("ReportSummary").Range("AY" & Rows.Count).End(xlUp).Row
Dim FaultLR As Long
FaultLR = Sheets("ReportSummary").Range("AN" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
With Sheets("ReportSummary")
.Unprotect Password:="ServiceODOS"
.Visible = True
fPath = ActiveWorkbook.Path & "\"
fName = .Range("S2") & "_" & "ReportSummary"
.Copy
Cells.Value = Cells.Value
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "CustomerData"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "SystemData"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "ServiceData"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "FailureData"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "PartsData"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "LaserPowerData"
Sheets.Add After:=Sheets(Sheets.Count)
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "CameraLightData"
Sheets("ReportSummary").Select
Columns("A:K").Select
Selection.Copy
Sheets("CustomerData").Select
ActiveSheet.Paste
Sheets("ReportSummary").Select
Columns("L:R").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("SystemData").Select
ActiveSheet.Paste
Sheets("ReportSummary").Select
Columns("S:AK").Select
Selection.Copy
Sheets("ServiceData").Select
ActiveSheet.Paste
Sheets("ReportSummary").Select
Range("AL1:AW" & FaultLR).Copy
Sheets("FailureData").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("ReportSummary").Select
Range("AX1:BD" & PartsLR).Copy
Sheets("PartsData").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("ReportSummary").Select
Columns("BE:BL").Select
Selection.Copy
Sheets("LaserPowerData").Select
ActiveSheet.Paste
Sheets("ReportSummary").Select
Columns("BM:BS").Select
Selection.Copy
Sheets("CameraLightData").Select
ActiveSheet.Paste
Sheets("ReportSummary").Activate
Range("A4").Select
Sheets("ReportSummary").Activate
Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWorkbook.SaveAs Filename:=fPath & fName & ".xls", FileFormat:=xlNormal
ActiveWindow.Close
.Visible = False
.Protect Password:="ServiceODOS"
End With
Sheets("Report").Activate
Application.ScreenUpdating = True
End Sub
The purpose of it is to copy a worksheet of one workbook and paste to another workbook, and then sub-divide the data into individual worksheets, and lastly renaming the new file and closing it. There are two dynamic ranges in the original file where the code attempts to find the last row of the data and copy the 'legitimate' data. The data ranges, called in the code PartsLR and FaultLR, have a maximum data range of 21 rows 31 rows, respectively. The purpose of the export is for me to in turn import the data into an Access database. With this code, somehow the range for PartLR is working OK but the FaultLR is considered as having data, so all 31 rows are being imported, even though most of them don't have data. I can't find where this is breaking down. Can anyone help? Thanks in advance.
Bookmarks