EXCEL檔案中的簡單VB編程,基本的存取方法

來源:互聯網
上載者:User
Private Sub CommandButton1_Click()
    For i = 1 To Sheets.Count - 1
    
        
        Dim shet
        Dim shetd
        shetd = "a" + Trim(str(i))
        shet = "b" + Trim(str(i))
        
        For j = 1 To 100
            
            Dim sss
            sss = "A" + Trim(str(j))    //數字轉換成字元,截取掉空格,拼合成一個儲存格地址
            
            
            Dim ccc
            ccc = Sheets(i).Range(sss).Value   //獲得某頁某個儲存格的內容
            
            Dim d
            d = Sheets(i).Name        //獲得某個sheet的名稱
            
            
            
            If ccc = "合計" Then
            
                Dim row
                row = "t" + Trim(str(j))
                
                Sheets("統計").Range(shetd) = d         //設定某個儲存格的值
                
                Sheets("統計").Range(shet) = Round(Sheets(i).Range(row).Value, 2)
                
            End If
        Next j
    Next i
End Sub

Private Sub CommandButton2_Click()
    For i = 1 To Sheets.Count - 1
    
        
        Dim shet
        Dim shetd
        shetd = "a" + Trim(str(i))
        shet = "b" + Trim(str(i))
        
        For j = 1 To 100
            
            Dim sss
            sss = "A" + Trim(str(j))
            
            
            Dim ccc
            ccc = Sheets(i).Range(sss).Value
            
            Dim d
            d = Sheets(i).Name
            
            
            
            If ccc = "平均" Then
            
                Dim row
                row = "t" + Trim(str(j))
                
                Sheets("統計").Range(shetd) = d
                
                Sheets("統計").Range(shet) = Round(Sheets(i).Range(row).Value, 2)
                
            End If
        Next j
    Next i
End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.