我想将范围从“D250”设置为始终更改的单元格
但我不能把变量设置为代码行!设置newRng = ws.Range(“D250:endRngMun”)endRngMun总是在改变......
Sub Compare()
Dim ws As Worksheet
Dim munCompt As Long
Dim totalMun As Long
Dim endRngMun As String
Set ws = Sheets("T1")
' find last row with data in Column B at current regioun starting at cell B10
With ws.Range("D250").CurrentRegion
munCompt = .Rows(.Rows.Count).Row
End With
Dim Rng As Range
Set Rng = ws.Range("D250:D" & munCompt)
' find last row inside the range, ignore values inside formulas
munCompt = Rng.Find(What:="*", _
After:=Range("D250"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
totalMun = Application.WorksheetFunction.CountA(Rng)
endRngMun = "D" & 250 + totalMun - 1
Dim newRng As Range
Set newRng = ws.Range("D250:endRngMun")
' for debug
Debug.Print newRng.Count
End Sub