我幾乎完全一樣的問題,因爲這一次(與礦,我需要來連接的值成單個文本字符串,而不是單個單元格!)
它不像Excel中那麼容易這應該是我想的。我的解決方案如下:)
Sub TransP()
Dim LastRow As Integer
Dim LastCol As Integer
LastRow = Worksheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
LastCol = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
'Clear cells from sheet2
Worksheets("Sheet2").Select
Cells.Select
Selection.ClearContents
'Copy full range from sheet 1
Worksheets("Sheet1").Select
Worksheets("Sheet1").Range(Cells(1, 1), Cells(LastRow, LastCol)).Select
Selection.Copy
'Paste into sheet 2
Worksheets("Sheet2").Select
ActiveSheet.Paste
LastRow = Worksheets("Sheet2").Cells(Rows.Count, 2).End(xlUp).Row
'Iteration to transpose and collate data together
For i = 2 To LastRow
If Cells(i, 2).Value = Cells(i + 1, 2).Value Then
LastCol = Worksheets("Sheet2").Cells(i, Columns.Count).End(xlToLeft).Column
Cells(i, LastCol + 1).Value = Cells(i + 1, 3).Value
Rows(i + 1 & ":" & i + 1).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
'Exit sub when it reaches the end (blank cell)
If Cells(i, 2).Value = "" Or Cells(i + 1, 2).Value = "" Then
Exit Sub
End If
Next
End Sub
你有任何代碼可以告訴我們嗎? – user1
我的宏記錄看起來像這樣,但當然它不涉及不同範圍(1-99)或循環: Sub transferclone() 表(「Tabelle1」)。選擇 範圍(「E2:E100」) 。選擇 Selection.Copy 表( 「Tabelle2」)選擇 Selection.PasteSpecial貼:= xlAll,操作:= xlNone,SkipBlanks:=假_ ,移調:=真 範圍( 「D4」)選擇 。表格(「Tabelle1」)。選擇 範圍(「E101:E199」)。選擇 Application.CutCopyMode = False Selection.Copy 表(「Tabelle2」)。選擇 Selection.PasteSpecial Pa ste:= xlAll,操作:= xlNone, End Sub – Nicholas