พอดีช่วงนี้กำลังอ่านหนังสือเรื่อง excel advance ก็เลยมาลองของนิดหน่อย
การทำ in-place analysis report
หลายๆคนคงต้องเสียเวลากับการทำ ตาราง Load combination อย่างนี้ ( http://image.ohozaa.com/view/1a57p )กันไม่มากก็น้อย
ผมก็เป็นคนนึง ที่เสียเวลาทำตาราง Load combination เป็นวันๆ(ในกรณีที่ลูกค้าไม่ได้ให้ตารางมาเป็น excel แต่ดันให้มาเป็นกระดาษอันแสนที่จะมองไม่ค่อยเห็น) ผมว่าหลายๆคนก็เคยเจอปัญหานี้มาก่อน
ผมได้ทำ macro excel ให้แปลงจาก command line จาก SACS มาเป็นตาราง excel เอามาฝากครับ
มันเป็นแค่ต้นแบบน่ะครับ ผิดพลาดอะไรก็ขออภัยด้วย อีกอย่างผมไม่ได้ security ไว้ ใครจะเอาไปพัฒนาต่อก็ได้ครับ แล้วเอามาแบ่งปันกันได้ครับ
ถ้ามี feedback ดี เดี๋ยวผมจะเอา macro excel อื่นมาฝากอีกครับ ตอนนี้กำลังทำ การจัดเรียง member uc, joint uc, basic load และอื่นๆ
เช่น แสดงผลของการ ananlysis ออกมาเป็นตารางสวยๆทันทีแค่copy sacslst มาไว้ในexcel เป็นต้น
วิธีใช้ก็ copy LCOMB line ใน SACS input file มาไว้ใน cell "A1" sheet 1
แล้วก็ตามรูปนี้เลยครับ
http://image.ohozaa.com/view/1a57h
ปล. มือใหม่น่ะครับ
Code มีดังนี้ครับ
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 1), Array(10, 1), Array(15, 1), Array(21, 1), _
Array(25, 1), Array(31, 1), Array(35, 1), Array(41, 1), Array(45, 1), Array(51, 1), Array( _
55, 1), Array(61, 1), Array(65, 1)), TrailingMinusNumbers:=True
Range("A1").Select
Do While Not IsEmpty(ActiveCell.Value)
If ActiveCell.Value <> "LCOMB" Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:SN5000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B:B" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:D5160")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveCell.Offset(0, 3).Select
Selection.Insert Shift:=xlToRight
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveCell.Offset(0, 3).Select
Selection.Insert Shift:=xlToRight
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveCell.Offset(0, 3).Select
Selection.Insert Shift:=xlToRight
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveCell.Offset(0, 3).Select
Selection.Insert Shift:=xlToRight
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveCell.Offset(0, 3).Select
Selection.Insert Shift:=xlToRight
a = 0
For i = 1 To 5
a = 3 + a
Range("B1").Select
ActiveCell.Offset(0, a).Select
If Not IsEmpty(ActiveCell.Value) Then
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, ActiveCell.Offset(0, 2)).Select
Selection.Cut
Range("B1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Insert Shift:=xlDown
Else
Exit For
End If
Next i
Range("A1").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C:C" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:D5160")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("C1").Select
Selection.End(xlDown).Select
If Not IsEmpty(ActiveCell.Offset(1, -1)) Then
Range(ActiveCell.Offset(1, -1), Selection.End(xlDown)).EntireRow.Delete
End If
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B:B" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:D5160")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("B1").Value = "Load comb"
Range("C1").Value = "Basic Load"
Range("D1").Value = "Factor"
ActiveCell.Columns("A:C").EntireColumn.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C2:R1048576C4", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet2!R2C2", TableName:="PivotTable4", DefaultVersion _
:=xlPivotTableVersion14
Sheets("Sheet2").Select
Cells(2, 2).Select
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Load comb")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Basic Load")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
"PivotTable4").PivotFields("Factor"), "Count of Factor", xlCount
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Count of Factor")
.Caption = "Max of Factor"
.Function = xlMax
.NumberFormat = "0.00"
End With
End Sub
