Failed to delete lines from the worksheet

  • Failed to delete lines from the worksheet, even if there are 500000 lines, you have to delete from B8 to V8 all.



    Code
    If question = vbYes Then
    
    Sheets("Planilha0").Select
    Celulas = Array("B8:V8")
    
    For i = 0 To UBound(Celulas)
        Range(Celulas(i)).ClearContents
    Next i
    
    End If
  • Go to Best Answer
  • Could you attach a copy of your file? It would be easier to see how your data is organized and to test possible solutions. Include a detailed explanation

    of what you want to do using a few examples from your data and referring to specific cells, rows, columns and sheets. De-sensitize the data if necessary.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • So, this worksheet is under development, little by little I'm tidying each item, this code would be for the button in red right when you open the worksheet, its function should be to delete all entries from B8 to V8, delete the entire lines.

    The writing of the button is in Portuguese, the native language of where I live, but it's this button right when you open the file, button in red.

  • Code
    Hello
    
    The "pergunta" variable is empty and the cycle is not executed.
    I add that the loop, if executed, clears the contents (.ClearContents) of columns A: F, 
    but does not delete (not .Delete).
    
    Hello,
    Mario
  • If you want to delete only row 8 from column B to column V try:

    Code
    Sub DeleteRow()
        Rows(8).Delete
    End Sub

    If you want to delete all the rows in your table, try:

    Code
    Sub DeleteRows()
        ActiveSheet.ListObjects("tabela1").DataBodyRange.Delete
    End Sub

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • If you want to delete only row 8 from column B to column V try:

    Code
    Sub DeleteRow()
        Rows(8).Delete
    End Sub

    If you want to delete all the rows in your table, try:

    Code
    Sub DeleteRows()
        ActiveSheet.ListObjects("tabela1").DataBodyRange.Delete
    End Sub

    Is it possible to include a message with a pop up window? "Are you sure you want to clear the worksheet? Yes or No"

    • Best Answer

    Try:

    Code
    Sub DeleteRows()
        If MsgBox("Are you sure you want to clear the worksheet?", vbYesNo) = vbYes Then
            ActiveSheet.ListObjects("tabela1").DataBodyRange.Delete
        End If
    End Sub

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!