我有多行数据,最后一列中的值需要移动到另一个新列。所以如果我的数据看起来像......
One |2. |5
Two. |The. |6
Three. |3. |
Then I need it to look like...
One |2. | |5
Two. |The. | |6
Three. | | |3
答案 0 :(得分:1)
在:
考虑:
Sub dural()
With ActiveSheet.UsedRange
nLastColumn = .Columns.Count + .Column - 1
Columns(nLastColumn).Copy Columns(nLastColumn + 1)
Columns(nLastColumn).Clear
End With
End Sub
之后:
答案 1 :(得分:0)
这完全符合您的要求,如果您不理解,请随时调查:
Sub LastClm()
Dim myRng As Range
Dim lRow, lClm, rCnt, cCnt As Integer
lRow = Sheets(4).Cells(Sheets(4).Rows.Count, 1).End(xlUp).Row
lClm = Sheets(4).Cells(1, Sheets(4).Columns.Count).End(xlToLeft).Column
'sets the last row regardless of missing information in the first column
Do Until Application.WorksheetFunction.CountA(Rows(lRow + 1)) = 0
lRow = lRow + 1
Loop
'sets the last column regardless of missing information in the first row
Do Until Application.WorksheetFunction.CountA(Columns(lClm + 1)) = 0
lClm = lClm + 1
Loop
'Loops through each row from back to front taking the first cell it sees with information in it
For rCnt = 1 To lRow
For cCnt = lClm To 1 Step -1
With Sheets(4)
If Application.WorksheetFunction.CountA(.Cells(rCnt, cCnt)) = 1 Then
.Cells(rCnt, lClm + 1).Value = .Cells(rCnt, cCnt)
.Cells(rCnt, cCnt).ClearContents
GoTo 1
End If
End With
Next cCnt
1
Next rCnt
End Sub