Guest User

Untitled

a guest
Apr 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' date: 190422
  2. ' autor: ***
  3. ' note: 處理tlm raw data用,初步擷取出有用的部份,以及作I-V圖
  4. '       後續需要人工除去不必要的資料,再執行"main_tlm_cal"
  5.  
  6. Sub main_tlm()
  7.  
  8.     找所需資料的開端
  9.    
  10.     Dim SetupTitle_index As Integer
  11.    
  12.     ' 找出SetupTitle的index
  13.    Cells(2, 28).Value = "=MATCH(""SetupTitle"",A:A, 0)"
  14.     SetupTitle_index = Cells(2, 28).Value
  15.        
  16.     ' counter 用來決定貼到哪一欄
  17.    Dim counter As Integer
  18.     For counter = 1 To 20
  19.         貼上資料 SetupTitle_index, (2 * counter - 1) + 6
  20.        
  21.         ' 刪除處理好的raw data
  22.        Range(Cells(1, 1), Cells(SetupTitle_index - 1, 4)).Delete xlUp
  23.        
  24.        
  25.         If Cells(1, 1) = "" Then
  26.             Exit For
  27.         End If
  28.        
  29.         找所需資料的開端
  30.     Next counter
  31.    
  32.     清除
  33.    
  34.     給予current編號
  35.    
  36.     作圖
  37.  
  38. End Sub
  39.  
  40. Sub 找所需資料的開端()
  41.     ' 找出DataName的index
  42.    Cells(2, 27).Value = "=MATCH(""DataName"",A:A, 0)"
  43.    
  44.     ' DataName上面的列,全部刪除
  45.    Dim dataname_index As Integer
  46.     dataname_index = Cells(2, 27).Value - 1
  47.     ' 刪除
  48.    Range("A1:D" & dataname_index).Delete xlUp
  49.  
  50. End Sub
  51.  
  52. Sub 貼上資料(nextdatarow As Integer, newpastecol As Integer)
  53.     Range(Cells(1, 2), Cells(nextdatarow - 1, 3)).Copy
  54.     Range(Cells(1, newpastecol), Cells(nextdatarow - 1, newpastecol)).PasteSpecial
  55. 'Range(Cells(1, 2), Cells(SetupTitle_index - 1, 2))
  56. End Sub
  57. Sub 清除()
  58.     Range("A:F").Delete
  59.     Dim i As Integer
  60.     Dim index As Integer
  61.     For i = 1 To 40
  62.         If Cells(1, i) = "" Then
  63.             index = i
  64.             Exit For
  65.         End If
  66.     Next i
  67.    
  68.     Range(Cells(1, index), Cells(10, index + 10)).Delete
  69.    
  70. End Sub
  71. Sub 給予current編號()
  72.     Dim i As Integer
  73.     For i = 2 To 20
  74.         If Cells(1, i) = "" Then
  75.             Exit For
  76.         ElseIf Cells(1, i) = " V1" Then
  77.             ' do nothing
  78.        ElseIf Cells(1, i) = "V1" Then
  79.             ' do nothing
  80.        Else
  81.             Cells(1, i).Value = "I" & i / 2
  82.         End If
  83.     Next i
  84.    
  85. End Sub
  86. Sub 作圖()
  87.     Range("A:A,B:B,D:D,F:F,H:H,J:J,L:L,N:N,P:P,R:R,T:T,V:V,X:X,Z:Z").Select
  88.     Range("P1").Activate
  89.     ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmooth).Select
  90.     ActiveChart.SetSourceData Source:=Range( _
  91.         "A:A,B:B,D:D,F:F,H:H,J:J,L:L,N:N,P:P,R:R,T:T,V:V,X:X,Z:Z" _
  92.         )
  93.     ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
  94.     ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
  95.     ActiveChart.SetElement (msoElementChartTitleNone)
  96.     ActiveChart.SetElement (msoElementLegendRight)
  97.     ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
  98.     ActiveChart.Axes(xlCategory).AxisTitle.Select
  99.     ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "V (V)"
  100.     Selection.Format.TextFrame2.TextRange.Characters.Text = "V (V)"
  101.     With Selection.Format.TextFrame2.TextRange.Characters(1, 5).ParagraphFormat
  102.         .TextDirection = msoTextDirectionLeftToRight
  103.         .Alignment = msoAlignCenter
  104.     End With
  105.     With Selection.Format.TextFrame2.TextRange.Characters(1, 5).Font
  106.         .BaselineOffset = 0
  107.         .Bold = msoFalse
  108.         .NameComplexScript = "+mn-cs"
  109.         .NameFarEast = "+mn-ea"
  110.         .Fill.Visible = msoTrue
  111.         .Fill.ForeColor.RGB = RGB(89, 89, 89)
  112.         .Fill.Transparency = 0
  113.         .Fill.Solid
  114.         .Size = 10
  115.         .Italic = msoFalse
  116.         .Kerning = 12
  117.         .Name = "+mn-lt"
  118.         .UnderlineStyle = msoNoUnderline
  119.         .Strike = msoNoStrike
  120.     End With
  121.     ActiveChart.Axes(xlValue).AxisTitle.Select
  122.     ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "I (A)"
  123.     Selection.Format.TextFrame2.TextRange.Characters.Text = "I (A)"
  124.     With Selection.Format.TextFrame2.TextRange.Characters(1, 5).ParagraphFormat
  125.         .TextDirection = msoTextDirectionLeftToRight
  126.         .Alignment = msoAlignCenter
  127.     End With
  128.     With Selection.Format.TextFrame2.TextRange.Characters(1, 5).Font
  129.         .BaselineOffset = 0
  130.         .Bold = msoFalse
  131.         .NameComplexScript = "+mn-cs"
  132.         .NameFarEast = "+mn-ea"
  133.         .Fill.Visible = msoTrue
  134.         .Fill.ForeColor.RGB = RGB(89, 89, 89)
  135.         .Fill.Transparency = 0
  136.         .Fill.Solid
  137.         .Size = 10
  138.         .Italic = msoFalse
  139.         .Kerning = 12
  140.         .Name = "+mn-lt"
  141.         .UnderlineStyle = msoNoUnderline
  142.         .Strike = msoNoStrike
  143.     End With
  144.     ' 設定位置
  145.    With ActiveChart.Parent
  146.     .Top = Range("D10").Top
  147.     .Left = Range("D10").Left
  148.     End With
  149.    
  150. End Sub
Advertisement
Add Comment
Please, Sign In to add comment