I have this Macro which works great with one major hitch. The idea here is that when a user inserts a row, it adds .01 to the end of the row. If they insert another row, it becomes .02.
The problem is that I was told everything in Column A would be seven digits. Well, that turned out to be wrong. So I converted all of Column A to seven "digits" with =TEXT((A1)+ "0000000").
However, when my Macro inserts a row, I lose the leading zeroes. This throws off susbsequent row insertions. Any ideas?
Sub InsertRow()
Dim a As Integer
Dim x As String
x = ActiveCell.Value
If Len(x) = 7 Then GoTo NoCountNumber:
On Error GoTo NoCountNumber:
a = CInt(Right(x, 2))
If a > 0 And a < 9 Then
a = a + 1
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = Left(x, Len(x) - 2) & CStr("0" & a)
End With
Application.CutCopyMode = False
Else
a = a + 1
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = Left(x, Len(x) - 2) & CStr(a)
End With
End If
GoTo Finish:
NoCountNumber:
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = x & ".01"
End With
Application.CutCopyMode = False
Finish:
End Sub
The problem is that I was told everything in Column A would be seven digits. Well, that turned out to be wrong. So I converted all of Column A to seven "digits" with =TEXT((A1)+ "0000000").
However, when my Macro inserts a row, I lose the leading zeroes. This throws off susbsequent row insertions. Any ideas?
Sub InsertRow()
Dim a As Integer
Dim x As String
x = ActiveCell.Value
If Len(x) = 7 Then GoTo NoCountNumber:
On Error GoTo NoCountNumber:
a = CInt(Right(x, 2))
If a > 0 And a < 9 Then
a = a + 1
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = Left(x, Len(x) - 2) & CStr("0" & a)
End With
Application.CutCopyMode = False
Else
a = a + 1
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = Left(x, Len(x) - 2) & CStr(a)
End With
End If
GoTo Finish:
NoCountNumber:
With ActiveCell
.EntireRow.Copy
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
.Offset(1, 0).Value = x & ".01"
End With
Application.CutCopyMode = False
Finish:
End Sub