查看完整版本: EXCEL VBA 新手求助選取偶數列
頁: [1]

特納圖 發表於 2016-10-15 11:07 PM

EXCEL VBA 新手求助選取偶數列

本帖最後由 特納圖 於 2016-10-15 11:08 PM 編輯

想請問各位
我手邊有幾萬筆像這樣排序的資料



需求是雙數列的儲存格(可能一格或兩格)的資料需到單數列的尾巴且最後要把雙數列刪除
想請問該如何寫VBA程式
拜託各位

<div></div>

rr09192084 發表於 2016-10-19 11:04 PM


Sub test()
    Dim i As Long, j As Integer, k As Integer
    Dim lastRow As Long
    lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
   
    For i = 2 To lastRow Step 2
      For j = 1 To 256
        If Cells(i, j) <> "" Then
          For k = 1 To 256
            If Cells(i - 1, k) = "" Then
              Cells(i - 1, k) = Cells(i, j)
              Cells(i, j) = ""
              Exit For
            End If
          Next k
        Else
          Exit For
        End If
      Next j
    Next i
    lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    Dim m As Integer
    m = lastRow
    While m > 1
      If Cells(m, 1) = "" Then
        Rows(m).Select
        Selection.Delete Shift:=xlUp
        m = m - 1
      Else
        m = m - 1
      End If
    Wend
End Sub
試試看這段VBA程式!...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div>
頁: [1]