Excel VBA设置单元格作为variables

我已阅读文章,导致我把第一行变成一个variables,但我也需要“n94”作为variables。 它总是7行,并在N列。 今后我必须重新编辑这6个数据线……试图连接备忘录笔记,并将其数据量过长。

Range("B101").Select Selection.Copy Range("N94").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Rows("95:101").Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp 

感谢您的任何帮助

它总是7行,并在N列

这是你正在尝试?

 Sub Sample() Dim ws As Worksheet Dim rng As Range '~~> Replace this with the actual sheet name Set ws = ThisWorkbook.Sheets("Sheet1") With ws Set rng = ActiveCell '<~~ From Comments below If (rng.Row - 7) < 1 Then MsgBox "Cannot Paste. Row Out of bounds" Exit Sub End If rng.Copy .Cells(rng.Row - 7, "N").PasteSpecial _ Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False '~~> Delete the rows. For example Rows("95:101") .Rows((rng.Row - 6) & ":" & rng.Row).Delete Shift:=xlUp End With End Sub