请问excel表格中,如何将A列、B列和C列自动排列组合,显示到D列(用VBA代码如何按A列型号排列组合到D列)
发布网友
发布时间:2022-08-21 14:01
我来回答
共2个回答
热心网友
时间:2023-11-24 00:18
答:我用VBA写了一小段代码实现了上述功能。要运行宏,可参阅WPS运行宏的方法。
Sub Demo()
Dim FirstRow As Long, LastRow As Long, i As Integer, j As Integer
Dim Cell As Range, DesRng As Range
Set DesRng = Range("D2")
For Each Cell In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(xlCellTypeConstants, 23)
FirstRow = Cell.Row
LastRow = Cell.End(xlDown).Row - 1
If Cell.End(xlDown).Row = Cells.Rows.Count Then
LastRow = Application.Max(Cells(Rows.Count, "B").End(xlUp).Row, Cells(Rows.Count, "C").End(xlUp).Row)
End If
For i = FirstRow To LastRow
If Not IsEmpty(Cells(i, "B")) Then
For j = FirstRow To LastRow
If Not IsEmpty(Cells(j, "C")) Then
DesRng = Cell & "+" & Cells(i, "B") & "+" & Cells(j, "C")
Set DesRng = DesRng.Offset(1, 0)
End If
Next j
End If
Next i
Next
MsgBox "转换完成", vbInformation, "提示"
End Sub
热心网友
时间:2023-11-24 00:18
这么复杂的问题,要给一些奖赏,大家才有兴趣回答追问我也想给,但只有2个财富值,无法送出啊!跪求!
追答你用的是WPS表格,先要确定是否能运行宏,不然白费工夫