[英]How to Delete Specific Cells in a User Specified Row
我正在尋求幫助以刪除用戶指定的行中的特定單元格 ( activecell.row
)。 我的代碼在當前選定的行下方插入一行。 我還想刪除該行中的幾個單元格而不刪除整行和所有公式。
Sub AddNewLine()
Dim ws As Worksheet
Dim rng As Range
Dim myVal As Integer
ActiveSheet.Unprotect
'~~> Set this to the relevant worksheet
Set ws = ActiveWorkbook.ActiveSheet
With ws
'~~> Set your range
Set rng = .Rows(ActiveCell.Row)
'~~> Copy the range
rng.Copy
'~~> Insert the range
rng.Offset(1).Insert Shift:=xlDown
'I would like to delete the values in these cells:
Range("G.25").ClearContents
Range("I25").ClearContents
Range("J25").ClearContents
Range("K25").ClearContents
End With
ActiveSheet.Protect
End Sub
謝謝你的幫助!
試試這個代碼:
Sub AddNewLine()
Dim ws As Worksheet
Dim rng As Range
Dim myVal As Integer
ActiveSheet.Unprotect
'~~> Set this to the relevant worksheet
Set ws = ActiveWorkbook.ActiveSheet
With ws
'~~> Set your range
Set rng = .Rows(ActiveCell.Row)
'~~> Copy the range
rng.Copy
'~~> Insert the range
rng.Offset(1).Insert Shift:=xlDown
'I would like to delete the values in these cells:
rng.Offset(1).Columns("G").ClearContents
rng.Offset(1).Columns("I:K").ClearContents
End With
ActiveSheet.Protect
End Sub
Sub AddNewLine()
Dim rng As Range
With ActiveSheet
.Unprotect
'~~> Set your range
Set rng = ActiveCell.EntireRow
'~~> Copy the range
rng.Copy
'~~> Insert the range
rng.Offset(1).Insert
'I would like to delete the values in these cells:
Intersect(.Range("G:G, I:K"), rng).ClearContents
.Protect
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.