delete rows between tow inputs numbers

C

Colin Hayes

Hi

I need help with a small macro.

I need to enter two numbers in message boxes , and then delete the rows
between the two input numbers.

If the second number is entered as 'last row' , then it would delete
between the first number entered and the bottom row , whatever number
row it may be.

Can someone help with some code?

Grateful for any help.



Best Wishes
 
J

James Ravenswood

Hi

I need help with a small macro.

I need to enter two numbers in message boxes , and then delete the rows
between the two input numbers.

If the second number is entered as 'last row' , then it would delete
between the first number entered and the bottom row , whatever number
row it may be.

Can someone help with some code?

Grateful for any help.

Best Wishes

How about:

Sub rowKiller()
Dim n1 As String, n2 As String, s As String
n1 = Application.InputBox(prompt:="enter first row", Type:=2)
n2 = Application.InputBox(prompt:="enter last row", Type:=2)
If n2 = "last row" Then
n2 = CStr(Rows.Count)
End If
s = n1 & ":" & n2
Rows(s).Delete
End Sub
 
C

Colin Hayes

How about:

Sub rowKiller()
Dim n1 As String, n2 As String, s As String n1 = Application.InputBox(prompt:="en
ter first row",
Type:=2) n2 = Application.InputBox(prompt:="enter last row", Type:=2)
If n2 = "last row" Then
n2 = CStr(Rows.Count)
End If
s = n1 & ":" & n2
Rows(s).Delete
End Sub


HI James

OK thanks for that. It works perfectly first time.

^_^


Best Wishes ,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top