Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Inserting A Row Into A Data Table

I have a table of data sorted by column A. Is there a way
to insert a row of data into this table in its proper
sorted position (so that after the insert operation the
data is still sorted)? The method I am using now is to
append the row of data at the bottom of the table, then
resort the table.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Inserting A Row Into A Data Table

Jeffrey,

It can be done but putting it at the bottom and doing a resort is probably
quicker and easier.

--
sb
"Jeffrey" wrote in message
...
I have a table of data sorted by column A. Is there a way
to insert a row of data into this table in its proper
sorted position (so that after the insert operation the
data is still sorted)? The method I am using now is to
append the row of data at the bottom of the table, then
resort the table.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inserting A Row Into A Data Table

Sub AAtester2()
Dim rng As Range
Dim res As Variant
Dim newValue as Long
NewValue = 1
If NewValue < Range("A2") Then
Rows(2).Insert
Range("A2") = NewValue
Else
Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))
res = Application.Match(NewValue, rng, 1)
If Not IsError(res) Then
rng(res + 1).EntireRow.Insert
rng(res + 1).Value = NewValue
End If
End If
End Sub

If these are dates, you will need to adjust


Sub AAtester3()
Dim rng As Range
Dim res As Variant
Dim newValue As Date
newValue = DateSerial(2003, 1, 10)
If newValue < Range("A2") Then
Rows(2).Insert
Range("A2") = newValue
Else
Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))
res = Application.Match(CLng(newValue), rng, 1)
If Not IsError(res) Then
rng(res + 1).EntireRow.Insert
rng(res + 1).Value = newValue
End If
End If
End Sub


--
Regards,
Tom Ogilvy



Jeffrey wrote in message
...
I have a table of data sorted by column A. Is there a way
to insert a row of data into this table in its proper
sorted position (so that after the insert operation the
data is still sorted)? The method I am using now is to
append the row of data at the bottom of the table, then
resort the table.

Thanks.



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
Inserting a table within a large worksheet TonyH[_2_] Excel Discussion (Misc queries) 2 September 7th 09 08:16 PM
inserting a calculated field in a pivot table. John B Excel Discussion (Misc queries) 0 April 6th 09 09:29 PM
Inserting formular in Table YMTEO Excel Discussion (Misc queries) 0 July 14th 08 11:13 AM
I would require help in inserting formulas in Pivot Table please. David Excel Discussion (Misc queries) 1 June 6th 07 01:10 AM
Pivot Table Macro not inserting all data fields [email protected] Excel Discussion (Misc queries) 0 October 27th 06 04:55 AM


All times are GMT +1. The time now is 07:06 PM.

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

About Us

"It's about Microsoft Excel"