SiamFarm.com
ชื่อผู้ใช้งาน  
รหัสผ่าน


สยามฟาร์ม SiamFarm
ขอเชิญเพื่อนๆพี่ๆน้องๆ แชร์เรื่องราวที่อาจมีประโยชน์ต่อเพื่อนมนุษย์ด้วยนะครับ

หน้า: [1]
  พิมพ์  
ผู้เขียน หัวข้อ: มีเครื่องมือช่วยให้ คนที่ใช้ SACS ทำ in-Place analysis ได้สะดวกขึ้นครับ  (อ่าน 6095 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
Akeng
ผู้หมวด
**

คะแนนความนิยม: 3
ออฟไลน์ ออฟไลน์

กระทู้: 28



ดูรายละเอียด
« เมื่อ: สิงหาคม 20, 2011, 06:22:23 pm »

พอดีช่วงนี้กำลังอ่านหนังสือเรื่อง 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


« แก้ไขครั้งสุดท้าย: สิงหาคม 20, 2011, 06:24:31 pm โดย Akeng » บันทึกการเข้า
Cindyvega
ผู้หมวด
**

คะแนนความนิยม: 0
ออฟไลน์ ออฟไลน์

กระทู้: 2


ดูรายละเอียด อีเมล์
« ตอบ #1 เมื่อ: มิถุนายน 27, 2018, 11:26:43 am »

อันนี้มีรุ่นที่พัฒนาแล้วหรือยังครับ
บันทึกการเข้า
หน้า: [1]
  พิมพ์  
 
กระโดดไป:  


* Share this topic......
For Webboard
(BBCode)
For Website/Blog
(HTML)