1

Now I am trying a VBA practice, but I discovered that there are different results between debugging mode and normal run mode(F5).

I want to make the colors that fill the cells shift to the right, so that it works well when I run it through debugging mode, but normal run mode doesn't deliver the same.

I can't find why the same code make different results. Thank you for your help.

Option Explicit

Sub Wave()

Dim StartRow As Integer, StartColumn As Integer, Width As Integer, Height As Integer
Dim i As Integer, j As Integer, k As Integer
Dim FirstColumn As Range, LastColumn As Range

StartRow = 1
StartColumn = 1
Width = 112
Height = 50
    
Range(Cells(StartRow, StartColumn), Cells(Height, Width)).Select
Selection.RowHeight = 10
Selection.ColumnWidth = 1

For i = 1 To Height
    For j = 1 To Width
        Cells(i, j).Interior.ColorIndex = (i + j) Mod 56 + 1 '
    Next j
Next i

For k = 1 To Width
    Columns(Width).Select
    Selection.Cut
    Columns(1).Select
    Selection.Insert Shift:=xlToRight
Next k

End Sub
Kimpro
  • 81
  • 2
  • 11
  • 1
    Start [here](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – BigBen Nov 14 '20 at 01:41
  • I tried also to avoid `select` and `activecell`, but I failed to realize the same effect with cut & paste by that way, so I should use `select` unwillingly. But I am going to try again with reference to the link that you give me. Thank you! – Kimpro Nov 14 '20 at 01:52
  • Use objects, you defined two range variables but never used them. To avoid select, try something like this: Instead of: `Columns(Width).Select` `Selection.Cut` `Columns(1).Select` `Selection.Insert Shift:=xlToRight` Use: `With Wsh` use worksheet object `.Columns(Width).Cut` `.Columns(1).Insert Shift:=xlToRight` `End with` – EEM Nov 14 '20 at 05:11

0 Answers0