Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Insert row on change of field - with input selection - not whole column

Sub ModifiedTest()
Dim myRow As Long
Dim StrtRow As Long
Dim myCol As Integer
Dim myRange As Range

Set myRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection

myCol = myRange.Column
StrtRow = myRange(65536).End(xlUp).Row

For myRow = StrtRow To 2 Step -1
If Cells(myRow, myCol).Value < Cells(myRow - 1, myCol).Value Then
Cells(myRow, myCol).EntireRow.Insert
End If
Next myRow
End Sub

What wrong with my range - I want only a selection from a column.or
can somebody propose me an alternative macro to make it work for a
selection in a column only.

Thxs



Original code is as per below:
Sub TryNow()
Dim myRow As Long
Dim StrtRow As Long
Dim myCol As Integer
Dim myRange As Range

Set myRange = Range("D:D")

myCol = myRange.Column
StrtRow = myRange(65536).End(xlUp).Row

For myRow = StrtRow To 2 Step -1
If Cells(myRow, myCol).Value < Cells(myRow - 1, myCol).Value Then
Cells(myRow, myCol).EntireRow.Insert
End If
Next myRow
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Insert row on change of field - with input selection - not whole c

Hi,
Try:

StrtRow = Cells(Rows.Count, myCol).End(xlUp).Row

HTH

"al007" wrote:

Sub ModifiedTest()
Dim myRow As Long
Dim StrtRow As Long
Dim myCol As Integer
Dim myRange As Range

Set myRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection

myCol = myRange.Column
StrtRow = myRange(65536).End(xlUp).Row

For myRow = StrtRow To 2 Step -1
If Cells(myRow, myCol).Value < Cells(myRow - 1, myCol).Value Then
Cells(myRow, myCol).EntireRow.Insert
End If
Next myRow
End Sub

What wrong with my range - I want only a selection from a column.or
can somebody propose me an alternative macro to make it work for a
selection in a column only.

Thxs



Original code is as per below:
Sub TryNow()
Dim myRow As Long
Dim StrtRow As Long
Dim myCol As Integer
Dim myRange As Range

Set myRange = Range("D:D")

myCol = myRange.Column
StrtRow = myRange(65536).End(xlUp).Row

For myRow = StrtRow To 2 Step -1
If Cells(myRow, myCol).Value < Cells(myRow - 1, myCol).Value Then
Cells(myRow, myCol).EntireRow.Insert
End If
Next myRow
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
How to insert row on Col A field change Cinco Excel Discussion (Misc queries) 2 July 9th 09 10:08 PM
Change Field On Pivot Table Using VBA Input Box Cue Excel Discussion (Misc queries) 0 July 4th 08 06:51 PM
Macro to change list box input range based on selection made in another cell Sue[_6_] Excel Programming 3 October 7th 04 06:45 PM
insert data into macro code from text input field? john_t_h[_15_] Excel Programming 1 January 16th 04 03:14 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


All times are GMT +1. The time now is 08:51 PM.

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"