我在電子表格上有一些數據。特別是我需要第一列中的TIME和第二列中的TIME取決於時間,出於奇怪的原因,當我將txt文件導入excel時,如果時間從上午10點到23.59,則時間在列A上時間在B中。 我試圖製作一個VBA腳本,可以讓我把所有的數據放在同一列(A)。 我的想法是: - 對於列中的所有行A - 如果單元格爲空,則在實際單元格中複製B單元格(同一行)的值(例如,如果A1爲空,則複製A1中的B1) - 停止從一列複製/粘貼行的單元格到另一個 - VBA
次測試()
Dim i As Integer
Dim lastRow As Long
Dim x, y As Integer
Dim rng As String
Sheets("Sheet1").Select
' count numer of recorsd (in the first column) - check the range
lastRow = Worksheets("Sheet1").Range("B:B").Cells.SpecialCells(xlCellTypeConstants).Count
For i = 1 To lastRow
If IsEmpty(Worksheets("Sheet1").Range(Cells(1, i))) Then Range(Cells(2, i)).Select: Range (Cells (1, i)).Copy: Range(Cells(1, i)).PasteSpecial: Range(Cells(2, i)).Clear
Next i
末次
我tryed做出頭,但它顯示了一個錯誤: 'run時錯誤'1004':
應用 - 定義的或對象定義的錯誤
有什麼想法?
你也應該把'i,x,y'從'Integer's改爲'Long's。整行將在行'32,767'後失敗,無論如何它們在內部轉換爲'Long':http://msdn.microsoft.com/zh-cn/library/aa164754。 – Ioannis