能写个代码,把当前工作表第1、2列的数据倒置吗?
vba吧
全部回复
仅看楼主
level 1
wawabird22 楼主
RT
2026年01月31日 01点01分 1
level 12
本人258000
2026年02月01日 01点02分 2
768 企鹅
2026年02月01日 01点02分
level 3
直接上豆包就可以给你干了
2026年02月02日 05点02分 3
吧务
level 11
Sub ReverseColumnsAB_Array() Dim ws As Worksheet Dim lastRow As Long Dim arrA() As Variant, arrB() As Variant Dim i As Long, j As Long Set ws = ActiveSheet lastRow = 网页链接 (ws.Rows.Count, 1).End(xlUp).Row ' 获取A列最后一行 ' 边界检查 If lastRow < 2 Then MsgBox "数据行数不足2行,无需倒置", vbInformation Exit Sub End If ' 读取数据到数组 arrA = ws.Range("A1:A" & lastRow).Value arrB = ws.Range("B1:B" & lastRow).Value ' 创建临时数组存储倒置结果 ReDim tempA(1 To lastRow, 1 To 1) ReDim tempB(1 To lastRow, 1 To 1) For i = 1 To lastRow j = lastRow - i + 1 tempA(i, 1) = arrA(j, 1) tempB(i, 1) = arrB(j, 1) Next i ' 写回工作表 ws.Range("A1:A" & lastRow).Value = tempA ws.Range("B1:B" & lastRow).Value = tempB MsgBox "A、B列数据已成功倒置!共处理 " & lastRow & " 行", vbInformation End Sub
2026年02月09日 00点02分 4
吧务
level 11
现在用 Ai写
2026年03月26日 01点03分 5
1