VBA解決繁瑣的比較問題

來源:互聯網
上載者:User

今天老大又給我了一個體力活,不過比query接觸的更底層了一點,將資料來源的資訊對象和原系統資訊對象進行匹配,有一個已經做好了原系統是800的傳輸規則。當我匹配完了之後一個很大的問題就是如何驗證,肉眼去驗證很容易出錯如果資料量很大的話更是如此。你我用兩個步驟解決了,第一步將傳輸規則的資料拷貝出來,sap好像只能一屏一屏的拷貝,暫時沒有發現更好的方法。第二個步驟用VBA寫一個程式將資料進行比較。excel的強大莫過於此了。我要比較的資料

拷貝到excel後資料如下:

也就是G列和C列的資料進行比較。那代碼就好寫了,VBA代碼如下:

為了方便大家複製:

Sub CheckString()
    Dim standard As String
    Dim compare As String
    Dim nextrow As Integer
    Dim message As String
    nextrow = 0
     With Worksheets("Sheet1").Range("C2")
       standard = .Offset(nextrow, 0).Value
       compare = .Offset(nextrow, 4).Value
        While standard ""
'             .Offset(nextrow, 1).Value = standard
             If standard = compare Then
                nextrow = nextrow + 1
                standard = .Offset(nextrow, 0).Value
                compare = .Offset(nextrow, 4).Value
             Else
                message = nextrow & compare
                MsgBox message
             End If
        Wend
    End With
    message = "you have compared" & nextrow & "rows! " & " and it is all correctet"
    MsgBox message
End Sub

最後得說一下,excel雖然強大,不過excel2007有一個非常明顯的bug。在excel裡任意一欄以輸入=77.1*850看看結果是多少。應該等於216減一65535,但是excel2007裡不是這個結果。

大家可以看下http://blogs.msdn.com/excel/archive/2007/09/25/calculation-issue-update.aspx我有空再研究研究這個問題。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.