Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public strPrefix As String
- Sub SensorList()
- '
- ' SensorList Macro
- '
- '''''''''''''''''''''''''''''''''''''''''''' Pre filter start for moving door switch Start''''''''''''''''''''''''''''''''
- x = ActiveSheet.UsedRange.Rows.Count
- y = 1
- TotalRows = ActiveSheet.UsedRange.Rows.Count
- For x = TotalRows To 1 Step -1
- If (InStr((Cells(x, 1).Value), "SR")) = 1 _
- And InStr((Cells(x, 2).Value), "DS") = 1 _
- And (InStr((Cells(x, 7).Value), "I")) = 1 Then
- Cells(x, (y + 1)).Select
- Selection.Copy
- Cells(x, y).Select
- ActiveSheet.Paste
- Application.CutCopyMode = False
- Cells(x, (y + 2)).Select
- Selection.Cut
- Cells(x, (y + 1)).Select
- ActiveSheet.Paste
- Application.CutCopyMode = False
- Else
- End If
- Next x
- '''''''''''''''''''''''''''''''''''''''''''Pre filter start for moving door switch End ''''''''''''''''''''''''''''
- ' Initialization
- GetPrefix
- InstList = Array("SENSORS", "HIGH VOLTAGE ELECTRICAL", "LOW VOLTAGE ELECTRICAL", "SAFETY") ' List of installation codes to be included in label file
- FamilyList = Array("DS", "DISC", "LS", "PB", "PE", "PRS", "PRX", "PS", "LSR", "DV", "CB") ' List of family codes to be included in label file
- Application.ScreenUpdating = False ' To avoid screen flicker. Set to True before exiting macro.
- SearchOnInst = 0 ' Set to 0 to search on Family. Set to 1 to search on Installation
- TotalRows = ActiveSheet.UsedRange.Rows.Count
- TolalCols = ActiveSheet.UsedRange.Columns.Count
- Tag = 0
- Desc = Array(0, 0, 0, 0, 0) ' Allow up to five description fields
- DescCount = 0
- Addr = 0
- Inst = 0
- ' Locate Description Column Headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If (InStr(1, Head$, "PLCDESC", 1)) > 0 Then
- Desc(DescCount) = Col
- DescCount = DescCount + 1
- End If
- Next Col
- ' Eliminate crap columns that AutoCAD creates
- Dim JunkRange As Range
- Set JunkRange = ActiveSheet.Columns(DescCount + 4)
- For Col = (DescCount + 5) To 214
- Set JunkRange = Union(JunkRange, ActiveSheet.Columns(Col))
- Next Col
- JunkRange.Delete Shift:=xlToLeft
- If DescCount > 2 Then
- ' Combine description columns into one
- ' For Row = 2 To TotalRows
- ' For DescIndex = 1 To DescCount - 1
- ' If Cells(Row, Desc(DescIndex)).Value <> "" Then
- ' Cells(Row, Desc(0)).Value = Cells(Row, Desc(0)).Value + " " + Cells(Row, Desc(DescIndex)).Value
- ' End If
- ' Next DescIndex
- ' Next Row
- ' Remove extra description columns
- For DescIndex = DescCount - 1 To 2 Step -1
- Columns(Desc(DescIndex)).Delete Shift:=xlToLeft
- Next DescIndex
- End If
- ' Locate remaining column headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If Head$ = "CMPTAG" Then
- Tag = Col
- ElseIf Head$ = "PLCADDR" Then
- Addr = Col
- ElseIf Head$ = "CMPINST" Then
- Inst = Col
- End If
- Next Col
- ' Format remaining columns
- ActiveSheet.Cells(1, Tag).Value = "TAG"
- If DescCount > 0 Then
- ActiveSheet.Cells(1, Desc(0)).Value = "DESC 1"
- End If
- If DescCount > 1 Then
- ActiveSheet.Cells(1, Desc(1)).Value = "DESC 2"
- End If
- ActiveSheet.Cells(1, Addr).Value = "ADDRESS"
- ActiveSheet.Rows(1).Font.Bold = True
- For Col = 1 To (DescCount + 3)
- ActiveSheet.Columns(Col).EntireColumn.AutoFit
- Next Col
- If SearchOnInst = 1 Then
- ' Test INST column for filter
- For Row = TotalRows To 2 Step -1
- InstCode$ = ActiveSheet.Cells(Row, Inst).Value
- Keep = False
- For i = 0 To UBound(InstList)
- If InstCode$ = InstList(i) Then
- Keep = True
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- Else
- ' Test TAG column for filter
- For Row = TotalRows To 2 Step -1
- CurrentTag$ = ActiveSheet.Cells(Row, Tag).Value
- Keep = False
- For i = 0 To UBound(FamilyList)
- If (InStr(1, CurrentTag$, FamilyList(i), 1)) = 1 Then
- Keep = True
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- End If
- ' Delete Installation code column - not wanted on labels
- If (Inst > 0) Then
- Columns(Inst).Delete
- End If
- ' Sort remaining entries based on first column
- Columns("A:D").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- ' Sort format for Excel 2007
- ' Columns("A:C").Select
- ' ActiveSheet.Sort.SortFields.Clear
- ' ActiveSheet.Sort.SortFields.Add Key:= _
- ' Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
- ' xlSortNormal
- ' With ActiveSheet.Sort
- ' .SetRange ActiveSheet.UsedRange
- ' .Header = xlYes
- ' .MatchCase = False
- ' .Orientation = xlTopToBottom
- ' .SortMethod = xlPinYin
- ' .Apply
- ' End With
- ' ############### Remove duplicate tag rows
- Columns("D:D").Select
- Selection.SpecialCells(xlCellTypeBlanks).Select
- Selection.EntireRow.Delete
- ' ############### End of Remove duplicate tag rows
- ' Move cursor
- Application.ScreenUpdating = True
- ActiveWindow.ScrollColumn = 1
- Cells(1, 1).Select
- ' Save as CSV file, preserving the original XLS file
- ' Prompt user for project number
- On Error GoTo ErrorHandler
- Path$ = ActiveWorkbook.Path
- 'MsgBox (Path$)
- DefaultNum$ = Left(ActiveWorkbook.Name, 5)
- If Not (DefaultNum$ Like "[0-9][0-9][0-9][0-9][0-9]") Then
- DefaultNum$ = ""
- End If
- ProjectNum$ = InputBox("Please enter the 5-digit project number:", "Project Number", DefaultNum$)
- 'GetPrefix
- Filename$ = Path$ + "\" + ProjectNum$ + "_Labels_4Line_Sensors.txt"
- ActiveWorkbook.SaveAs Filename:=Filename$, FileFormat:=xlCSV, CreateBackup:=False
- Exit Sub
- ErrorHandler:
- MsgBox ("Error while saving file." & Chr(13) & Chr(10) & "File was not saved!")
- Resume Next
- End Sub
- Sub ComponentList()
- '
- ' ComponentList Macro
- '
- ' Initialization
- GetPrefix
- If strPrefix = Null Then
- OneLineFamilyList = Array(("M"), ("AC"), ("DISC"), ("LS"), ("SOL"), ("CR"), ("PLC"), ("RECPT"), ("FAN"), ("XF"), ("PS"), ("PV"), ("CP"), ("ES"), ("VFD"), ("DRIVE"), ("SV"), ("PDB"), ("SR")) ' List of family codes to be included in one-line label file
- TwoLineFamilyList = Array(("FU"), ("CB")) ' List of family codes to be included in two-line label file
- ThreeLineFamilyList = Array(("MTR"), ("HB"), ("CBM")) ' List of family codes to be included in three-line label file
- ValveFamilyList = Array("SOL") ' List of family codes to be included in special valve label file
- Else
- OneLineFamilyList = Array((strPrefix & "M"), (strPrefix & "AC"), (strPrefix & "DISC"), (strPrefix & "LS"), (strPrefix & "CR"), (strPrefix & "SOL"), (strPrefix & "PLC"), (strPrefix & "RECPT"), (strPrefix & "FAN"), (strPrefix & "CP"), (strPrefix & "XF"), (strPrefix & "PS"), _
- (strPrefix & "PV"), (strPrefix & "ES"), (strPrefix & "VFD"), (strPrefix & "DRIVE"), (strPrefix & "SV"), (strPrefix & "PDB"), (strPrefix & "SR")) ' List of family codes to be included in one-line label file
- TwoLineFamilyList = Array((strPrefix & "FU"), (strPrefix & "CB")) ' List of family codes to be included in two-line label file
- ThreeLineFamilyList = Array((strPrefix & "MTR"), (strPrefix & "HB"), (strPrefix & "CBM")) ' List of family codes to be included in three-line label file
- ValveFamilyList = Array((strPrefix & "SOL")) ' List of family codes to be included in special valve label file
- End If
- ''EDITED BY ANDREW
- Dim TwoLineFamilyListOmit As Variant
- TwoLineFamilyListOmit = Array(("CBL"), ("TAG"), ("DESC"))
- Application.ScreenUpdating = True ' To avoid screen flicker. Set to True before exiting macro. --previous value:false
- TotalRows = ActiveSheet.UsedRange.Rows.Count
- TolalCols = ActiveSheet.UsedRange.Columns.Count
- TotalSheets = Sheets.Count
- If TotalSheets > 1 Then
- For Sh = TotalSheets To 2 Step -1
- Sheets(Sh).Delete
- Next Sh
- End If
- Sheets(1).Activate
- Sheets(1).Name = "Raw List"
- Sheets("Raw List").Select
- Sheets("Raw List").Copy After:=Sheets(1)
- Sheets(2).Select
- Sheets(2).Name = "1-Lines"
- Sheets("Raw List").Select
- Sheets("Raw List").Copy After:=Sheets(2)
- Sheets(3).Select
- Sheets(3).Name = "2-Lines"
- Sheets("Raw List").Select
- Sheets("Raw List").Copy After:=Sheets(3)
- Sheets(4).Select
- Sheets(4).Name = "3-Lines Motors"
- Sheets("Raw List").Select
- Sheets("Raw List").Copy After:=Sheets(4)
- Sheets(5).Select
- Sheets(5).Name = "Valves"
- ' Valve Procedure
- Sheets(5).Select
- Tag = 0
- Desc = Array(0, 0, 0, 0, 0) ' Allow up to five description fields
- DescCount = 0
- Inst = 0
- ' Locate Description Column Headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If (InStr(1, Head$, "DESC", 1)) > 0 Then
- Desc(DescCount) = Col
- DescCount = DescCount + 1
- End If
- Next Col
- ' Eliminate crap columns that AutoCAD creates
- Dim JunkRange As Range
- Set JunkRange = ActiveSheet.Columns(DescCount + 3)
- For Col = (DescCount + 3) To 214
- Set JunkRange = Union(JunkRange, ActiveSheet.Columns(Col))
- Next Col
- JunkRange.Delete Shift:=xlToLeft
- If DescCount > 2 Then
- ' Combine description columns into one
- ' For Row = 2 To TotalRows
- ' For DescIndex = 1 To DescCount - 1
- ' If Cells(Row, Desc(DescIndex)).Value <> "" Then
- ' Cells(Row, Desc(0)).Value = Cells(Row, Desc(0)).Value + " " + Cells(Row, Desc(DescIndex)).Value
- ' End If
- ' Next DescIndex
- ' Next Row
- ' Remove extra description columns
- For DescIndex = DescCount - 1 To 2 Step -1
- Columns(Desc(DescIndex)).Delete Shift:=xlToLeft
- Next DescIndex
- End If
- ' Locate remaining column headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If Head$ = "TAGNAME" Then
- Tag = Col
- ElseIf Head$ = "INST" Then
- Inst = Col
- End If
- Next Col
- ' Format remaining columns
- ActiveSheet.Cells(1, Tag).Value = "TAG"
- If DescCount > 0 Then
- ActiveSheet.Cells(1, Desc(0)).Value = "DESC 1"
- End If
- If DescCount > 1 Then
- ActiveSheet.Cells(1, Desc(1)).Value = "DESC 2"
- End If
- ActiveSheet.Rows(1).Font.Bold = True
- For Col = 1 To (DescCount + 3)
- ActiveSheet.Columns(Col).EntireColumn.AutoFit
- Next Col
- ' Test TAG column for filter
- For Row = TotalRows To 2 Step -1
- CurrentTag$ = ActiveSheet.Cells(Row, Tag).Value
- Keep = False
- For i = 0 To UBound(ValveFamilyList)
- If (InStr(1, CurrentTag$, ValveFamilyList(i), 1)) = 1 Then
- Keep = True
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- ' Delete Installation code column - not wanted on labels
- ActiveSheet.Columns(Inst).Delete
- ' Sort remaining entries based on first column
- Columns("A:C").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- ' Move cursor
- Cells(1, 1).Select
- ActiveWindow.ScrollColumn = 1
- ' #############################################################################
- ' 3-Line Procedure
- Sheets(4).Select
- Tag = 0
- Desc = Array(0, 0, 0, 0, 0) ' Allow up to five description fields
- DescCount = 0
- Inst = 0
- ' Locate Description Column Headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If (InStr(1, Head$, "DESC", 1)) > 0 Then
- Desc(DescCount) = Col
- DescCount = DescCount + 1
- End If
- Next Col
- ' Eliminate crap columns that AutoCAD creates
- Set JunkRange = ActiveSheet.Columns(DescCount + 3)
- For Col = (DescCount + 3) To 214
- Set JunkRange = Union(JunkRange, ActiveSheet.Columns(Col))
- Next Col
- JunkRange.Delete Shift:=xlToLeft
- If DescCount > 2 Then
- ' Combine description columns into one
- ' For Row = 2 To TotalRows
- ' For DescIndex = 1 To DescCount - 1
- ' If Cells(Row, Desc(DescIndex)).Value <> "" Then
- ' Cells(Row, Desc(0)).Value = Cells(Row, Desc(0)).Value + " " + Cells(Row, Desc(DescIndex)).Value
- ' End If
- ' Next DescIndex
- ' Next Row
- ' Remove extra description columns
- For DescIndex = DescCount - 1 To 2 Step -1
- Columns(Desc(DescIndex)).Delete Shift:=xlToLeft
- Next DescIndex
- End If
- ' Locate remaining column headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If Head$ = "TAGNAME" Then
- Tag = Col
- ElseIf Head$ = "INST" Then
- Inst = Col
- End If
- Next Col
- ' Format remaining columns
- ActiveSheet.Cells(1, Tag).Value = "TAG"
- If DescCount > 0 Then
- ActiveSheet.Cells(1, Desc(0)).Value = "DESC 1"
- End If
- If DescCount > 1 Then
- ActiveSheet.Cells(1, Desc(1)).Value = "DESC 2"
- End If
- ActiveSheet.Rows(1).Font.Bold = True
- For Col = 1 To (DescCount + 3)
- ActiveSheet.Columns(Col).EntireColumn.AutoFit
- Next Col
- ' Test TAG column for filter
- For Row = TotalRows To 2 Step -1
- CurrentTag$ = ActiveSheet.Cells(Row, Tag).Value
- Keep = False
- For i = 0 To UBound(ThreeLineFamilyList)
- If (InStr(1, CurrentTag$, ThreeLineFamilyList(i), 1)) = 1 Then
- Keep = True
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- ' Delete Installation code column - not wanted on labels
- ActiveSheet.Columns(Inst).Delete
- ' Sort remaining entries based on first column
- Columns("A:C").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- ' Move cursor
- Cells(1, 1).Select
- ActiveWindow.ScrollColumn = 1
- ' #############################################################################
- ' 2-Line Procedure
- Sheets(3).Select
- Tag = 0
- Desc = Array(0, 0, 0, 0, 0) ' Allow up to five description fields
- DescCount = 0
- Inst = 0
- ' Locate Description Column Headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If (InStr(1, Head$, "DESC", 1)) > 0 Then
- Desc(DescCount) = Col
- DescCount = DescCount + 1
- End If
- Next Col
- ' Eliminate crap columns that AutoCAD creates
- Set JunkRange = ActiveSheet.Columns(DescCount + 3)
- For Col = (DescCount + 3) To 214
- Set JunkRange = Union(JunkRange, ActiveSheet.Columns(Col))
- Next Col
- JunkRange.Delete Shift:=xlToLeft
- If DescCount > 1 Then
- ' Combine description columns into one
- ' For Row = 2 To TotalRows
- ' For DescIndex = 1 To DescCount - 1
- ' If Cells(Row, Desc(DescIndex)).Value <> "" Then
- ' Cells(Row, Desc(0)).Value = Cells(Row, Desc(0)).Value + " " + Cells(Row, Desc(DescIndex)).Value
- ' End If
- ' Next DescIndex
- ' Next Row
- ' Remove extra description columns
- For DescIndex = DescCount - 1 To 1 Step -1
- Columns(Desc(DescIndex)).Delete Shift:=xlToLeft
- Next DescIndex
- End If
- ' Locate remaining column headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If Head$ = "TAGNAME" Then
- Tag = Col
- ElseIf Head$ = "INST" Then
- Inst = Col
- End If
- Next Col
- ' Format remaining columns
- ActiveSheet.Cells(1, Tag).Value = "TAG"
- If DescCount > 0 Then
- ActiveSheet.Cells(1, Desc(0)).Value = "DESCRIPTION"
- End If
- ActiveSheet.Rows(1).Font.Bold = True
- For Col = 1 To (DescCount + 3)
- ActiveSheet.Columns(Col).EntireColumn.AutoFit
- Next Col
- ' Test TAG column for filter
- For Row = TotalRows To 2 Step -1
- CurrentTag$ = ActiveSheet.Cells(Row, Tag).Value
- Keep = False
- For i = 0 To UBound(TwoLineFamilyList)
- If (InStr(1, CurrentTag$, TwoLineFamilyList(i), 1)) = 1 Then
- Keep = True
- End If
- Next i
- ''ANDREW
- For i = 0 To UBound(TwoLineFamilyListOmit)
- If (InStr(1, CurrentTag$, TwoLineFamilyListOmit(i), 1)) = 1 Then
- Keep = False
- Exit For
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- '###############################################################################################################################################################
- ' TotalRows = ActiveSheet.UsedRange.Rows.Count
- 'x = 4000
- 'y = 1
- ' For x = TotalRows To 1 Step -1
- ' Cells(x, y).Select ' Add Line Below to add more text filter
- ' If ((InStr((Cells(x, y).Value), "CBL"))) = 1 Then
- ' Selection.EntireRow.Delete
- ' End If
- ' Next x
- ' Cells(1, y).Select
- '###############################################################################################################################################################
- ' Delete Installation code column - not wanted on labels
- ActiveSheet.Columns(Inst).Delete
- ' Sort remaining entries based on first column
- Columns("A:C").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- ' Move cursor
- Cells(1, 1).Select
- ActiveWindow.ScrollColumn = 1
- ' #############################################################################
- ' 1-Line Procedure
- Sheets(2).Select
- Tag = 0
- Desc = Array(0, 0, 0, 0, 0) ' Allow up to five description fields
- DescCount = 0
- Inst = 0
- ' Locate Description Column Headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If (InStr(1, Head$, "DESC", 1)) > 0 Then
- Desc(DescCount) = Col
- DescCount = DescCount + 1
- End If
- Next Col
- ' Eliminate crap columns that AutoCAD creates
- Set JunkRange = ActiveSheet.Columns(DescCount + 3)
- For Col = (DescCount + 3) To 214
- Set JunkRange = Union(JunkRange, ActiveSheet.Columns(Col))
- Next Col
- JunkRange.Delete Shift:=xlToLeft
- If DescCount > 0 Then
- ' Combine description columns into one
- ' For Row = 2 To TotalRows
- ' For DescIndex = 1 To DescCount - 1
- ' If Cells(Row, Desc(DescIndex)).Value <> "" Then
- ' Cells(Row, Desc(0)).Value = Cells(Row, Desc(0)).Value + " " + Cells(Row, Desc(DescIndex)).Value
- ' End If
- ' Next DescIndex
- ' Next Row
- ' Remove extra description columns
- For DescIndex = DescCount - 1 To 0 Step -1
- Columns(Desc(DescIndex)).Delete Shift:=xlToLeft
- Next DescIndex
- End If
- ' For 1-Line labels, remove description column
- ' Columns(Desc(0)).Delete Shift:=xlToLeft
- ' Locate remaining column headers
- For Col = 1 To 8 ' Max of eight columns to find
- Head$ = ActiveSheet.Cells(1, Col).Value
- If Head$ = "TAGNAME" Then
- Tag = Col
- ElseIf Head$ = "INST" Then
- Inst = Col
- End If
- Next Col
- ' Format remaining columns
- ActiveSheet.Cells(1, Tag).Value = "TAG"
- ActiveSheet.Cells(1, Desc(0)).Value = "DESCRIPTION"
- ActiveSheet.Rows(1).Font.Bold = True
- For Col = 1 To (DescCount + 3)
- ActiveSheet.Columns(Col).EntireColumn.AutoFit
- Next Col
- ' Test TAG column for filter
- For Row = TotalRows To 2 Step -1
- CurrentTag$ = ActiveSheet.Cells(Row, Tag).Value
- Keep = False
- For i = 0 To UBound(OneLineFamilyList)
- If (InStr(1, CurrentTag$, OneLineFamilyList(i), 1)) = 1 Then
- Keep = True
- End If
- Next i
- For i = 0 To UBound(TwoLineFamilyList)
- If (InStr(1, CurrentTag$, TwoLineFamilyList(i), 1)) = 1 Then
- Keep = False
- End If
- Next i
- For i = 0 To UBound(ThreeLineFamilyList)
- If (InStr(1, CurrentTag$, ThreeLineFamilyList(i), 1)) = 1 Then
- Keep = False
- End If
- Next i
- For i = 0 To UBound(ValveFamilyList)
- If (InStr(1, CurrentTag$, ValveFamilyList(i), 1)) = 1 Then
- Keep = False
- End If
- Next i
- If Not Keep Then
- Rows(Row).Delete
- End If
- Next Row
- ' Delete Installation code column - not wanted on labels
- ActiveSheet.Columns(Inst).Delete
- ' Remove duplicate ############################################################################################ Added By MJH ###############################################################
- Cells(1, 1).Select
- Columns("A:A").Select
- ActiveSheet.Range("$A$1:$A$2000").RemoveDuplicates Columns:=1, Header:=xlYes
- ' #############################################################################################################################################################################
- '###############################################################################################################################################################
- TotalRows = ActiveSheet.UsedRange.Rows.Count
- x = 4000
- y = 1
- For x = TotalRows To 1 Step -1
- Cells(x, y).Select ' Add Line Below to add more text filter
- If ((InStr((Cells(x, y).Value), "CBL"))) = 1 Then
- Selection.EntireRow.Delete
- End If
- Next x
- Cells(1, y).Select
- '###############################################################################################################################################################
- ' Sort remaining entries based on first column
- Columns("A:C").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- ' Move cursor
- Cells(1, 1).Select
- ActiveWindow.ScrollColumn = 1
- Application.ScreenUpdating = True
- Sheets(1).Activate
- ActiveWindow.ScrollColumn = 1
- Cells(1, 1).Select
- ' Save as CSV file, preserving the original XLS file
- ' Prompt user for project number
- On Error GoTo ErrorHandler
- Path$ = ActiveWorkbook.Path
- 'MsgBox (Path$)
- DefaultNum$ = Left(ActiveWorkbook.Name, 5)
- If Not (DefaultNum$ Like "[0-9][0-9][0-9][0-9][0-9]") Then
- DefaultNum$ = ""
- End If
- ProjectNum$ = InputBox("Please enter the 5-digit project number:", "Project Number", DefaultNum$)
- 'GetPrefix
- Filename$ = Path$ + "\" + ProjectNum$ + "_Components.xls"
- Filename1$ = Path$ + "\" + ProjectNum$ + "_Labels_1Line_Panel.txt"
- Filename2$ = Path$ + "\" + ProjectNum$ + "_Labels_2Line_Fuses.txt"
- Filename3$ = Path$ + "\" + ProjectNum$ + "_Labels_3Line_Motors.txt"
- Filename4$ = Path$ + "\" + ProjectNum$ + "_Labels_Valves.txt"
- Sheets(1).Select
- ActiveWorkbook.SaveAs Filename:=Filename$, _
- FileFormat:=xlExcel7, Password:="", WriteResPassword:="", _
- ReadOnlyRecommended:=False, CreateBackup:=False
- Sheets(2).Select
- ActiveWorkbook.SaveAs Filename:=Filename1$, FileFormat:=xlCSV, CreateBackup:=False
- Sheets(3).Select
- ActiveWorkbook.SaveAs Filename:=Filename2$, FileFormat:=xlCSV, CreateBackup:=False
- Sheets(4).Select
- ActiveWorkbook.SaveAs Filename:=Filename3$, FileFormat:=xlCSV, CreateBackup:=False
- Sheets(5).Select
- ActiveWorkbook.SaveAs Filename:=Filename4$, FileFormat:=xlCSV, CreateBackup:=False
- Exit Sub
- ErrorHandler:
- MsgBox ("Error while saving file." & Chr(13) & Chr(10) & "File was not saved!")
- Resume Next
- End Sub
- Sub WireLabels()
- '
- ' WireLabels Macro
- '
- '
- ' Initialization
- Application.ScreenUpdating = False ' To avoid screen flicker. Set to True before exiting macro.
- GetPrefix
- ' Sort entries
- Range("A1").Select
- Selection.Cut
- Range("H19").Select
- ActiveSheet.Paste
- Rows("1:1").Select
- Selection.Delete Shift:=xlUp
- Columns("A:A").Select
- Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
- Rows("1:1").Select
- Selection.Insert Shift:=xlDown
- Range("H19").Select
- Selection.Cut
- Range("A1").Select
- ActiveSheet.Paste
- Application.ScreenUpdating = True
- ' Save as XLS file, preserving the original XLS file
- ' Prompt user for project number
- On Error GoTo ErrorHandler
- Path$ = ActiveWorkbook.Path
- 'MsgBox (Path$)
- DefaultNum$ = Left(ActiveWorkbook.Name, 5)
- If Not (DefaultNum$ Like "[0-9][0-9][0-9][0-9][0-9]") Then
- DefaultNum$ = ""
- End If
- ProjectNum$ = InputBox("Please enter the 5-digit project number:", "Project Number", DefaultNum$)
- 'GetPrefix
- Filename$ = Path$ + "\" + ProjectNum$ + "_Wire_Labels.xls"
- ActiveWorkbook.SaveAs Filename:=Filename$, FileFormat:=xlExcel7, CreateBackup:=False
- Exit Sub
- ErrorHandler:
- MsgBox ("Error while saving file." & Chr(13) & Chr(10) & "File was not saved!")
- Resume Next
- End Sub
- Sub GetPrefix()
- strPrefix = InputBox("Please Enter a special Prefix or leave blank for normal naming")
- End Sub
- Sub Macro_Terminal_Numbers_Export()
- '
- ' Macro_Wire_Label_Export Macro
- ' Exporting terminal markers to notepad
- '
- '------------------------
- ' Definitions
- '------------------------
- Dim myfile As String
- Dim sheet_Number As Integer
- 'myfile = sheet_Number & ".txt"
- Dim filepath As String
- Dim celldata As String
- Dim CurrentRow, LastRow As Integer
- Dim Number_Of_Cells_to_Copy As Integer
- Dim Z As Boolean
- '------------------------
- ' start of code
- '------------------------
- ' CHANGED BY ANDREW
- sheet_Number = 1
- Number_Of_Cells_to_Copy = 200 '''''
- LastRow = 2
- Worksheets("Sheet1").Activate
- Do
- 'highlight the necessary area
- CurrentRow = LastRow
- LastRow = LastRow + Number_Of_Cells_to_Copy
- 'open the file and past the contents
- myfile = Application.DefaultFilePath & "\Terminal_Markers" & sheet_Number & ".txt"
- Open myfile For Output As #1
- 'write the data
- For x = CurrentRow To LastRow
- Print #1, Range("A" & CurrentRow).Value
- CurrentRow = CurrentRow + 1
- Next x
- Close #1
- sheet_Number = sheet_Number + 1
- LastRow = LastRow + 1
- Application.CutCopyMode = False
- Loop Until ActiveSheet.Range("A" & LastRow).Value = ""
- MsgBox ("The files are located in My Documents. Move them to your project folder on J:")
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement