我需要帮助来创建一个宏,该宏将清除所选行的内容,但仅清除A至J列,我可以清除整行,但这并不是很有用,因为该行上有多个表。
请帮助
谢谢!
答案 0 :(得分:1)
Application.Intersect(Selection.EntireRow, Selection.Worksheet.Columns("A:J")).ClearContents
答案 1 :(得分:1)
一行:
Option Explicit
Sub test()
Dim RowNo As Long
With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed
RowNo = Selection.Row '<- Get row number
.Range("A" & RowNo & ":J" & RowNo).ClearContents '<- Clear range A to J of the selected line
End With
End Sub
多行:
Option Explicit
Sub test()
Dim rng As Range
With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed
For Each rng In Selection.Rows
.Range("A" & rng.Row & ":J" & rng.Row).ClearContents
Next
End With
End Sub
答案 2 :(得分:0)
您可以遍历selectin中的每个单元格,并清除其内容:
Sub test()
Dim R As Range
For Each R In Selection:
If R.Column <= 10 Then
R.ClearContents
End If
Next
End Sub
Column
小于10意味着位于列A
到J
之间。