Macro Crashing Excel, Never used to until I added range part


New Member
Apr 11, 2013
Every time I run this macro it causes my Excel to crash. I am trying to take data from one sheet and re-arrange the data on a different sheet. I want to be able to clear all the data on the second sheet before it starts copying the data over.

Any ideas on how I can fix this?

Sub ConvertSingleLine()
      Dim x As Long
      Dim Sheet1TotalRows As Long
      Dim Sheet2TotalRows As Long
      Dim Sheet2Row As Long
      Sheet1TotalRows = Sheets(1).Cells.SpecialCells(xlCellTypeLastCell).Row
      Sheet2TotalRows = Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Row
      Sheets(2).Range("A2:AH" & Sheet2TotalRows).Clear
      Sheet2Row = 1
      For x = 1 To Sheet1TotalRows
        Select Case Sheets(1).Cells(x, 1).Value
            Case "   Tier: Core Certified", "   Tier: SPG Lite", "   Tier: SPG Classic", "   Tier: Service Lite"
            Sheet2Row = Sheet2Row + 1
            Sheets(2).Cells(Sheet2Row, 2).Value = Sheets(1).Cells(x, 1).Value
            Sheets(2).Cells(Sheet2Row, 1).Value = Sheets(1).Cells(x - 1, 1).Value
            Sheets(2).Cells(Sheet2Row, 3).Value = Sheets(1).Cells(x - 1, 2).Value
            Sheets(2).Cells(Sheet2Row, 4).Value = Sheets(1).Cells(x - 1, 3).Value
            Sheets(2).Cells(Sheet2Row, 5).Value = Sheets(1).Cells(x - 1, 4).Value
            Sheets(2).Cells(Sheet2Row, 6).Value = Sheets(1).Cells(x - 1, 5).Value
            Sheets(2).Cells(Sheet2Row, 7).Value = Sheets(1).Cells(x, 2).Value
            Sheets(2).Cells(Sheet2Row, 8).Value = Sheets(1).Cells(x, 3).Value
            Sheets(2).Cells(Sheet2Row, 9).Value = Sheets(1).Cells(x, 4).Value
            Sheets(2).Cells(Sheet2Row, 10).Value = Sheets(1).Cells(x, 5).Value
            Sheets(2).Cells(Sheet2Row, 11).Value = Sheets(1).Cells(x + 1, 2).Value
            Sheets(2).Cells(Sheet2Row, 12).Value = Sheets(1).Cells(x + 1, 3).Value
            Sheets(2).Cells(Sheet2Row, 13).Value = Sheets(1).Cells(x + 1, 4).Value
            Sheets(2).Cells(Sheet2Row, 14).Value = Sheets(1).Cells(x + 1, 5).Value
            Sheets(2).Cells(Sheet2Row, 15).Value = Sheets(1).Cells(x + 2, 2).Value
            Sheets(2).Cells(Sheet2Row, 16).Value = Sheets(1).Cells(x + 2, 3).Value
            Sheets(2).Cells(Sheet2Row, 17).Value = Sheets(1).Cells(x + 2, 4).Value
            Sheets(2).Cells(Sheet2Row, 18).Value = Sheets(1).Cells(x + 2, 5).Value
            Sheets(2).Cells(Sheet2Row, 19).Value = Sheets(1).Cells(x + 3, 2).Value
            Sheets(2).Cells(Sheet2Row, 20).Value = Sheets(1).Cells(x + 3, 3).Value
            Sheets(2).Cells(Sheet2Row, 21).Value = Sheets(1).Cells(x + 3, 4).Value
            Sheets(2).Cells(Sheet2Row, 22).Value = Sheets(1).Cells(x + 3, 5).Value
            Sheets(2).Cells(Sheet2Row, 23).Value = Sheets(1).Cells(x + 4, 2).Value
            Sheets(2).Cells(Sheet2Row, 24).Value = Sheets(1).Cells(x + 4, 3).Value
            Sheets(2).Cells(Sheet2Row, 25).Value = Sheets(1).Cells(x + 4, 4).Value
            Sheets(2).Cells(Sheet2Row, 26).Value = Sheets(1).Cells(x + 4, 5).Value
            Sheets(2).Cells(Sheet2Row, 27).Value = Sheets(1).Cells(x + 5, 2).Value
            Sheets(2).Cells(Sheet2Row, 28).Value = Sheets(1).Cells(x + 5, 3).Value
            Sheets(2).Cells(Sheet2Row, 29).Value = Sheets(1).Cells(x + 5, 4).Value
            Sheets(2).Cells(Sheet2Row, 30).Value = Sheets(1).Cells(x + 5, 5).Value
            Sheets(2).Cells(Sheet2Row, 31).Value = Sheets(1).Cells(x + 6, 2).Value
            Sheets(2).Cells(Sheet2Row, 32).Value = Sheets(1).Cells(x + 6, 3).Value
            Sheets(2).Cells(Sheet2Row, 33).Value = Sheets(1).Cells(x + 6, 4).Value
            Sheets(2).Cells(Sheet2Row, 34).Value = Sheets(1).Cells(x + 6, 5).Value
        End Select

End Sub


Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.


Well-known Member
May 25, 2010
Duplicated data based on code, ran and didn't crash on me. However.....

I would use .clearcontents instead of .clear

.clear will clear formats and everything where .clearcontents only clears the contents of a cell, not anything else attached to the cell. Could possibly have an issue with .clear however....

There has been an issue I've seen before where something becomes corrupt in the workbook and code starts doing funky things. If the above does not fix the issue then....

My suggestions fwiw....

1. copy code off to notepad and save it.
2. reboot PC
3. start a fresh new workbook and bring your data in.
4. Copy your code in from notebook

Run it and see if that resolves the issue. Don't bring anything in directly from the old workbook. If need be, save the old workbook as a csv and import it from the csv to the new workbook.

If it is still crashing after that. Uninstall and reinstall Excel.

If it is still crashing after that it's probably time to find a new job. :) Just kidding.
Upvote 0

Forum statistics

Latest member

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back