none
Repeatedly: 1) deleting a same-width block of columns, then 2) moving left 10 columns RRS feed

  • Question

  • Hello,

    I am trying to undertake these 2 steps repeatedly with the following code:

    Public Sub DeleteColumnsRepeatedly(ByVal R As Range)

                Dim I As Integer
                I = R.Columns.Count
                For Count As Integer = 1 To 3
                    R.EntireColumn.Delete()
                    R.Offset(0, -10).Select()
                Next

    End Sub

    The assumption is that the user has highlighted a block of columns before running this.

    The first column block deletion occurs successfully, but the Offset line crashes. I think that this is because I have already deleted the original range, so there is no frame of reference to offset from. How can I achieve such a deletion, but retain my frame of reference for offsetting?

    Many thanks.

    Keith



    R K Howard

    Tuesday, November 13, 2018 1:31 PM

Answers

All replies

  • Hi Keith,

    Please refer to the following links:

    Excel vba move columns and preserve widths

    Match, delete automatically shift cells to left and report column of matching cell

    Move Column to the Left

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, November 14, 2018 2:27 AM
  • Hi Keith,

    Thanks for your asking. Please remember to mark the replies as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

     

    Best Regards,

     

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Thursday, November 15, 2018 6:50 AM