Hello dear experts.
I would greatly appreciate your help with this problem that I have to insert a column to the left in the row if below the value in Range(x) of the cell is not equal to one. I have tried many ways, but the routine inserts many columns to the right.
Could you help me with this case, please?
In advance, I am very grateful for your valuable help.
The code I wrote is the following:
Sub InsertColumns()
Dim myCell As Range
Dim MyRange As Range
Set MyRange = ActiveSheet.Rows(5).SpecialCells(xlCellTypeConstants, xlNumbers)
For Each myCell In MyRange
x = myCell.Address(False, False)
MsgBox "x: " & x
Range(x).Select
For i = 1 To 1 Step -1
With Range(x)
.EntireColumn.Insert
.Offset(0, -1).ColumnWidth = 5
End With
Next
Next
Range("A1").Select
End Sub
Thank you very mcuh in advance.
I would greatly appreciate your help with this problem that I have to insert a column to the left in the row if below the value in Range(x) of the cell is not equal to one. I have tried many ways, but the routine inserts many columns to the right.
Could you help me with this case, please?
In advance, I am very grateful for your valuable help.
The code I wrote is the following:
Sub InsertColumns()
Dim myCell As Range
Dim MyRange As Range
Set MyRange = ActiveSheet.Rows(5).SpecialCells(xlCellTypeConstants, xlNumbers)
For Each myCell In MyRange
x = myCell.Address(False, False)
MsgBox "x: " & x
Range(x).Select
For i = 1 To 1 Step -1
With Range(x)
.EntireColumn.Insert
.Offset(0, -1).ColumnWidth = 5
End With
Next
Next
Range("A1").Select
End Sub
Inserting Columns.xlsm | |||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AN | AO | AP | AQ | AR | AS | AT | AU | |||
5 | 2008 | 2013 | 2014 | 2016 | 2017 | 2018 | |||||||||||||||||||||||||||||||||||||||||||
6 | Departamento | Municipio | 21 | 11 | 12 | 13 | 14 | 15 | 16 | 3 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ||
7 | Baja Verapaz | Cubulco | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
8 | Baja Verapaz | El Chol | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
9 | Baja Verapaz | Granados | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
10 | Baja Verapaz | Purulha | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
11 | Baja Verapaz | Rabinal | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
12 | Baja Verapaz | Salama | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
13 | Baja Verapaz | San Jeronimo | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
14 | Baja Verapaz | San Miguel Chicaj | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||||||||||
Cosecha 3 |
Thank you very mcuh in advance.