Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Nedd Help with an input box

Below is a macro that I use to insert blank lines after the value in Column A
changes. I need to be able to select which column I want the macro to
evaluate. I am thinking that an input box is the easiest way, but do not know
how to do it. Thanks!

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") < Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Nedd Help with an input box

Sub InsertRows()
Dim i As Integer
Dim rng as Range
Dim A as Long
On Error resume Next
set rng = Application.InputBox("Select column using mouse",Type:=8)
On Error goto 0
if rng is nothing then
msgbox "No column selected - terminating"
exit sub
End if
A = rng.Column
For i = Cells(Rows.Count, A).End(xlUp).Row To 2 Step -1
If Cells(i, A) < Cells(i + 1, A) Then
Cells(i + 1, A).EntireRow.Insert
End If
Next i
End Sub

--
Regards,
Tom Ogilvy

"jeffbert" wrote in message
...
Below is a macro that I use to insert blank lines after the value in

Column A
changes. I need to be able to select which column I want the macro to
evaluate. I am thinking that an input box is the easiest way, but do not

know
how to do it. Thanks!

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") < Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Nedd Help with an input box

This code will allow you to select a cell or column with a mouse and uses
that

Sub InsertRows()
Dim cRows As Long
Dim i As Integer
Dim cCol As Range

Set cCol = Application.InputBox("Select a cell or colun", Type:=8)

For i = Cells(Rows.Count, cCol.Column).End(xlUp).Row To 2 Step -1
If Cells(i, cCol.Column) < Cells(i + 1, "A") Then
Cells(i + 1, cCol.Column).EntireRow.Insert
End If
Next i
End Sub

--

HTH

RP

"jeffbert" wrote in message
...
Below is a macro that I use to insert blank lines after the value in

Column A
changes. I need to be able to select which column I want the macro to
evaluate. I am thinking that an input box is the easiest way, but do not

know
how to do it. Thanks!

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") < Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Nedd Help with an input box

Thanks for the great responses. I got Tom's to work, but Bob yours seems to
be looking at all columns instead of just one. I appreciate the help!!


"Bob Phillips" wrote:

This code will allow you to select a cell or column with a mouse and uses
that

Sub InsertRows()
Dim cRows As Long
Dim i As Integer
Dim cCol As Range

Set cCol = Application.InputBox("Select a cell or colun", Type:=8)

For i = Cells(Rows.Count, cCol.Column).End(xlUp).Row To 2 Step -1
If Cells(i, cCol.Column) < Cells(i + 1, "A") Then
Cells(i + 1, cCol.Column).EntireRow.Insert
End If
Next i
End Sub

--

HTH

RP

"jeffbert" wrote in message
...
Below is a macro that I use to insert blank lines after the value in

Column A
changes. I need to be able to select which column I want the macro to
evaluate. I am thinking that an input box is the easiest way, but do not

know
how to do it. Thanks!

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") < Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Nedd Help with an input box

There is a typo in Bob's code:

If Cells(i, cCol.Column) < Cells(i + 1, "A") Then

should be

If Cells(i, cCol.Column) < Cells(i + 1, cCol.Column) Then

--
Regards,
Tom Ogilvy


"jeffbert" wrote in message
...
Thanks for the great responses. I got Tom's to work, but Bob yours seems

to
be looking at all columns instead of just one. I appreciate the help!!


"Bob Phillips" wrote:

This code will allow you to select a cell or column with a mouse and

uses
that

Sub InsertRows()
Dim cRows As Long
Dim i As Integer
Dim cCol As Range

Set cCol = Application.InputBox("Select a cell or colun", Type:=8)

For i = Cells(Rows.Count, cCol.Column).End(xlUp).Row To 2 Step -1
If Cells(i, cCol.Column) < Cells(i + 1, "A") Then
Cells(i + 1, cCol.Column).EntireRow.Insert
End If
Next i
End Sub

--

HTH

RP

"jeffbert" wrote in message
...
Below is a macro that I use to insert blank lines after the value in

Column A
changes. I need to be able to select which column I want the macro to
evaluate. I am thinking that an input box is the easiest way, but do

not
know
how to do it. Thanks!

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") < Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
nedd to change column headings from numbers back to letters chucklinda525 New Users to Excel 2 December 29th 06 05:16 PM
I nedd help setting up a database on my customers Casper Excel Discussion (Misc queries) 2 July 1st 06 04:07 AM
I nedd my autofill options to always default to "copy cells" Christel Excel Discussion (Misc queries) 0 March 2nd 05 11:35 AM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Excel Programming 4 December 8th 03 03:22 PM
Nedd help on my function in VBA keawee[_2_] Excel Programming 1 October 28th 03 05:04 AM


All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"