2015年7月29日 星期三

729 note

if 類型一
if     條件式  then
   [程序區塊]
end if

if 類型二
if  條件式   x>=10 and y<=20 then
   [程序區塊1]
else
   [程式區塊2]
end if


1.x=20    y=30  =>執行區塊2
2.x=25    y=10  =>執行區塊1

if 類型三
if  條件式   x>=90 then
   [程序區塊1]
elseif    條件式  x>=80  then
   [程式區塊2]
elseif    條件式 x>=70   then
   [程式區塊3]
else
   [程式區塊4]
end  if

架構圖
                      資料互通
試算表
Application
Workbooks
Worksheets
Sheets
Cells
Range
Charts

VBA
1.Label
2.TexttBox
3.CheckBox
4.OptionButton
5.CommandButton
6.ScrollBar
7.ComboBox
8.ListBox
9.Image


模組表單
工作表1
worksheets("工作表1"),sheet("工作表1"),sheets(1)
Cells(1,1)
 選取Sheets(1).Cells(1,1).select
取值Dim s as String
        s=Sheets(1).Cells(1,1).Value
給值
      Sheets(1).Cells(1,1).Value=5600
----------------------------------------------------------------
Sub cellselect()
'    Sheets(1).Cells(2, 1).Select
'    Dim s As String
'    s = Sheets(1).Cells(2, 1).Value
'    MsgBox s
    Dim sump As Integer
    sump = Sheets(1).Cells(2, 5).Value + Sheets(1).Cells(3, 5).Value + Sheets(1).Cells(4, 5).Value
'    MsgBox sump
    Sheets(1).Cells(5, 5).Value = sump
End Sub
-------------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim p As Integer
    If Target.Column = 5 And Target.Row >= 2 And Target.Row < 5 Then
        p = Target.Value
        Sheets(1).Rows(Target.Row).Select
    '    MsgBox p
        If p >= 4000 Then
            MsgBox CStr(p) + "大於等於4000"
        Else
            MsgBox CStr(p) + "未達預設值"
        End If
    End If
End Sub
--------------------------------------------------------------------------------------
Sub info()
    Dim rcount As Integer
    Dim fcount As Integer
 
    rcount = Worksheets("工作表1").UsedRange.Rows.Count
    fcount = Worksheets("工作表1").UsedRange.Columns.Count
    MsgBox CStr(rcount) + ":" + CStr(fcount)
End Sub
-----------------------------
Private Sub CommandButton1_Click()
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Dim total As Integer
    Dim avg As Single
 
    Dim rcount As Integer
    rcount = Worksheets("工作表1").UsedRange.Rows.Count
    MsgBox rcount
 
   If TextBox1.Value <> "" And TextBox2.Value <> "" And TextBox3.Value <> "" Then
        a = CInt(TextBox1.Value)
        b = CInt(TextBox2.Value)
        c = CInt(TextBox3.Value)
        total = a + b + c
        TextBox4.Value = CStr(total)
     
        avg = total / 3
        TextBox5.Value = CStr(Format(avg, ".00"))
     
'        Sheets(1).Cells(rcount + 10, 1).Value = TextBox1.Value
'        Sheets(1).Cells(rcount + 10, 2).Value = TextBox2.Value
'        Sheets(1).Cells(rcount + 10, 3).Value = TextBox3.Value
'        Sheets(1).Cells(rcount + 10, 4).Value = TextBox4.Value
'        Sheets(1).Cells(rcount + 10, 5).Value = TextBox5.Value
    Else
        MsgBox "資料不完整請重新輸入"
        If TextBox1.Value = "" Then
            TextBox1.Activate
        ElseIf TextBox2.Value = "" Then
            TextBox2.Activate
        ElseIf TextBox3.Value = "" Then
            TextBox3.Activate
        End If
     
    End If
 
 
End Sub

沒有留言:

張貼留言