于治善VBA雙迴圈Loop與JavaScript迴圈

VBA迴圈畫圓

VBA迴圈畫圖程式碼


'拷貝自https://excelatfinance.com/xlf19/xlf-...
'Dr Ian O'Connor, CPA. - located in Victoria, Australia.
'2021/11/29劉任昌指導我從
Option Explicit
Const topleft As String = "C5"  ' anchor cell
Const diam As Integer = 180     ' points

Sub xlfAddCircle1()
Dim shp As Shape
Dim TLCleft As Double 'local variables區域變數
Dim TLCtop As Double
 
        TLCleft = Range(topleft).Left
        TLCtop = Range(topleft).Top
 
        Set shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _
                                              Left:=TLCleft, Top:=TLCtop, _
                                              Width:=diam, Height:=diam)
        With shp
                .Fill.Visible = msoFalse
                .Line.Weight = 10
                .Line.ForeColor.Brightness = 0.789
                .ThreeD.BevelTopType = msoBevelCircle
        End With
End Sub
Sub 于治善()
Dim shp As Shape '宣告dim 變數shp是圖形shpae
Dim TLCleft As Double 'local variables區域變數
Dim TLCtop As Double
 
        TLCleft = 10
        TLCtop = 10
 
        Set shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _
                                              Left:=TLCleft, Top:=TLCtop, _
                                              Width:=diam, Height:=diam)
        With shp
                .Fill.Visible = msoFalse
                .Line.Weight = 10
                .Line.ForeColor.Brightness = 0.789
                .ThreeD.BevelTopType = msoBevelCircle
        End With
End Sub
Sub 于治善777()

Dim shp As Shape '宣告dim 變數shp是圖形shape
Dim x As Double '宣告 x 是倍精度double
Dim y As Double '宣告 y 是倍精度double
Dim i As Integer '選告整數i
 For i = 1 To 20
        x = 20 * i
        y = 20 * i
Set shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _
                                      Left:=x, Top:=y, _
                                      Width:=diam, Height:=diam)
        With shp
                .Fill.Visible = msoFalse
                .Line.Weight = 25
                .Line.ForeColor.Brightness = 0.777
                .ThreeD.BevelTopType = msoBevelCircle
        End With
  Next
       With Cells(1, 1) 'with 固定前面的物件end with
                .Value = "于治善"
                .Interior.Color = RGB(0, 0, 0)
                With .Font
                  .Size = 16
                  .Bold = True
                  .Color = RGB(111, 225, 145)
                End With
        End With
End Sub
Sub 刪除()
Dim shp As Shape
   For Each shp In ActiveSheet.Shapes 'Shp 共用的物件宣告成全域變數
      shp.Delete
   Next
End Sub
  

VBA AddShpae語法

  • expression.AddShape(試算表.AddShape)
    1. Type:圖表類型
    2. Left:距離左
    3. Top:距離上
    4. Width:寬度
    5. Height:高度

    JavaScript 雙迴圈

    輸出

    Excel VBA 雙迴圈

    Excel VBA 雙迴圈程式碼

    Option Explicit '必須宣告所有變數variables
    Dim i, j As Integer '宣告dimension i,j 是整數 integer
    
    
    Public Sub 于治善()
     Cells(1, 1).Value = "于治善讚讚"
     Cells(1, 1).Font.Size = 20
     Cells(1, 1).Interior.Color = RGB(128, 0, 0)
     Cells(1, 1).Font.Color = RGB(255, 255, 255)
     End Sub
    
    
    Public Sub 于治善迴圈()
    For i = 2 To 10
    For j = 1 To 6
      Cells(i, j).Value = (2010 + i) & "年" & j & "月"
    Next
    Next
    End Sub
    

    RGB顏色控制

    檔案前頭程式碼

    留言

    這個網誌中的熱門文章

    于治善SVG,Excel資料表

    于治善 Excel樞紐分析 weekday