我几乎完全一样的问题,因为这一次(与矿,我需要来连接的值成单个文本字符串,而不是单个单元格!)
它不像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