我在电子表格上有一些数据。特别是我需要第一列中的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