ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA: Insert rows (https://www.excelbanter.com/excel-programming/440823-vba-insert-rows.html)

Karti[_2_]

VBA: Insert rows
 
Hi,
I am using the following VBA code to insert a number of rows starting from
the value contained in cells(5,3) and ends before or on cells(10,3) the
values are always in ascending order and in series. like 12, 13,1 4 etc. I
am getting a type mismatch error in the last line of code. It will be great
if someone can help me out with this.

Sub main()
Dim i As Integer
Dim value1 As Integer
Dim value2 As Integer
value1 = Cells(5, 3).Value
For i = 1 To 5
If Cells(5 + i, 3) < "" Then
value2 = Cells(5 + i, 3).Value
'MsgBox value2
End If
Next i
'MsgBox value2
Rows("value1:value2").Insert shift:=xlDown


End Sub



Karti[_2_]

Insert rows
 
Sorry for posting, found the answer
rows(value1 & ":" & value2).insert shift:=xlDown

"Karti" wrote in message
...
Hi,
I am using the following VBA code to insert a number of rows starting
from the value contained in cells(5,3) and ends before or on cells(10,3)
the values are always in ascending order and in series. like 12, 13,1 4
etc. I am getting a type mismatch error in the last line of code. It will
be great if someone can help me out with this.

Sub main()
Dim i As Integer
Dim value1 As Integer
Dim value2 As Integer
value1 = Cells(5, 3).Value
For i = 1 To 5
If Cells(5 + i, 3) < "" Then
value2 = Cells(5 + i, 3).Value
'MsgBox value2
End If
Next i
'MsgBox value2
Rows("value1:value2").Insert shift:=xlDown


End Sub






All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com