excel 中如何用宏实现:选择、复制、翻转、粘贴、删除。 需要高手帮忙
发布网友
发布时间:2022-05-01 12:53
我来回答
共4个回答
热心网友
时间:2023-10-13 12:16
用工作表改变事件来做
Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$G$1" Then
arr = [a10:f10]
arr1 = [g1:g6]
Sheets("sheet2").Range("a1:f1") = arr '复制
Sheets("sheet2").Range("a2:f2") = Application.Transpose(arr1) '转置G1:G6
Rows("1:1").ClearContents '删除第一行
Columns("G:G").ClearContents '删除第G列
End If
End Sub
热心网友
时间:2023-10-13 12:16
你可以使用录制宏的方式将你的上述操作过程录制下来。
再进去看看宏代码。
热心网友
时间:2023-10-13 12:17
选定(整个要转置的区域),复制,选择粘贴,转置
热心网友
时间:2023-10-13 12:17
Sheet1的Worksheet_SelectionChange事件程序如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i1 As Integer, j1 As Integer, i2 As Integer
Dim i As Integer, j As Integer
If Sheet2.Range("A65536").End(xlUp).Row() = 1 Then
i2 = 1
Else
i2 = Sheet2.Range("A65536").End(xlUp).Row() + 1
End If
i1 = Target.Row
j1 = Target.Column
For j = 1 To 6
Sheet2.Cells(i2, j) = Sheet1.Cells(i1, j)
Next j
i2 = Sheet2.Range("A65536").End(xlUp).Row() + 1
For i = 1 To 6
Sheet2.Cells(i2, i) = Sheet1.Cells(i, j1)
Next i
End Sub
热心网友
时间:2023-10-13 12:16
用工作表改变事件来做
Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$G$1" Then
arr = [a10:f10]
arr1 = [g1:g6]
Sheets("sheet2").Range("a1:f1") = arr '复制
Sheets("sheet2").Range("a2:f2") = Application.Transpose(arr1) '转置G1:G6
Rows("1:1").ClearContents '删除第一行
Columns("G:G").ClearContents '删除第G列
End If
End Sub
热心网友
时间:2023-10-13 12:16
你可以使用录制宏的方式将你的上述操作过程录制下来。
再进去看看宏代码。
热心网友
时间:2023-10-13 12:17
选定(整个要转置的区域),复制,选择粘贴,转置
热心网友
时间:2023-10-13 12:17
Sheet1的Worksheet_SelectionChange事件程序如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i1 As Integer, j1 As Integer, i2 As Integer
Dim i As Integer, j As Integer
If Sheet2.Range("A65536").End(xlUp).Row() = 1 Then
i2 = 1
Else
i2 = Sheet2.Range("A65536").End(xlUp).Row() + 1
End If
i1 = Target.Row
j1 = Target.Column
For j = 1 To 6
Sheet2.Cells(i2, j) = Sheet1.Cells(i1, j)
Next j
i2 = Sheet2.Range("A65536").End(xlUp).Row() + 1
For i = 1 To 6
Sheet2.Cells(i2, i) = Sheet1.Cells(i, j1)
Next i
End Sub