Answers for "excel vba delete range of cells from active cell"

VBA
2

excel vba delete rows in range

' Removes 3rd row
ThisWorkbook.Worksheets(1).Rows(3).EntireRow.Delete
' Just to clear cells without removing the row
ThisWorkbook.Worksheets("Feuil1").Rows(3).Cells.ClearContents
' Removes 3rd row of a range
Range("My_RANGE").Rows(3).EntireRow.Delete
Posted by: Guest on January-15-2021
2

excel vba what happens to range objects if user deletes cells

'Your code will raise a 'Runtime error 424: Object required'
'if a user deletes a range that your code has an open
'object reference to:

Set r = [a1]
Stop
'Now delete the first row and continue...
  
MsgBox r		'<--displays: Runtime error 424: Object required


'To avoid this problem, use the following VBA function to 
'test the validity of a range before accessing it:  

Function InvalidRangeReference(r As Range) As Boolean
    On Error Resume Next
    If r.Count = 0 Then InvalidRangeReference = Err
End Function
  
'-------------------------------------------------------------------- 
  
Set r = [a1]
Stop
'Now delete the first row and continue...
If InvalidRangeReference(r) Then Set r = [a1]

'Now you have a brand new reference to A1.
MsgBox r      	'<--works perfectly
Posted by: Guest on March-31-2020

Code answers related to "excel vba delete range of cells from active cell"

Code answers related to "VBA"

Browse Popular Code Answers by Language