Skip to main content

Conas an dáta a shórtáil go huathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú in Excel? 

In Excel, an Sórtáil is féidir le feidhm cabhrú leat dáta a shórtáil in ord ardaitheach nó íslitheach de réir mar is gá duit. Ach níl sé dinimiciúil, má tá an dáta curtha in eagar agat agus ansin dáta nua a chur leis, bheadh ​​ort é a shórtáil arís. An bhfuil aon bhealaí maithe gasta ann chun an dáta a shórtáil agus tú ag iontráil dáta nua gach uair ar bhileog oibre?

Dáta sórtála uathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú de réir na foirmle

Dáta sórtála uathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú le cód VBA


mboilgeog cheart gorm saighead Dáta sórtála uathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú de réir na foirmle

Mar shampla, an dáta bunaidh i gColún A, is féidir leis an bhfoirmle seo a leanas cabhrú leat an dáta nó aon teaghráin téacs eile a shórtáil i gcolún cúntóra nua bunaithe ar an gcolún a theastaíonn uait a shórtáil, déan mar a leanas le do thoil:

1. Iontráil an fhoirmle seo:

=INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,"<="&$A$2:$A$15),0)) isteach i gcill bhán in aice le do cholún dáta, C2, mar shampla, agus ansin brúigh Ctrl + Shift + Iontráil eochracha le chéile, agus gheobhaidh tú seicheamh uimhreacha, ansin tarraing an láimhseáil líonta síos go dtí na cealla is mian leat a úsáid, féach an scáileán:

nótaí: San fhoirmle thuas: A2: A15 an bhfuil do raon dáta bunaidh ar mhaith leat a shórtáil go huathoibríoch.

doc autosort faoi dháta 1

2. Ansin formáidigh na huimhreacha mar fhormáid dáta trí chliceáil Dáta Gearr ó na Go ginearálta liosta anuas faoin Baile cluaisín, féach an scáileán:

doc autosort faoi dháta 2

3. Ansin athraíodh na huimhreacha seicheamh go formáid an dáta, agus tá an dáta bunaidh curtha in eagar freisin, féach an scáileán:

doc autosort faoi dháta 3

4. As seo amach, nuair a bheidh tú ag iontráil dáta nua nó ag athrú an dáta i gcolún A, sórtálfar an dáta i gcolún C in ord ardaitheach go huathoibríoch, féach an scáileán:

doc autosort faoi dháta 4


mboilgeog cheart gorm saighead Dáta sórtála uathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú le cód VBA

Is féidir leis an gcód VBA seo a leanas cabhrú leat an dáta sa cholún bunaidh a shórtáil go huathoibríoch nuair a iontrálann tú dáta nua nó an dáta a athrú de réir mar is gá duit.

1. Téigh an bhileog oibre ar mhaith leat an dáta a shórtáil go huathoibríoch nuair a iontrálann tú nó má athraíonn tú dáta.

2. Cliceáil ar dheis ar an táb bileog, agus roghnaigh Féach an cód ón roghchlár comhthéacs, sa popped amach Microsoft Visual Basic d’Fheidhmchláir fuinneog, cóipeáil agus greamaigh an cód seo a leanas sa bán Modúil fuinneog, féach an scáileán:

Cód VBA: sórtáil uathoibríoch nuair a dhéantar an dáta a iontráil nó a athrú:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    On Error Resume Next
    If Application.Intersect(Target, Application.Columns(1)) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    Range("A1").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
                                        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

doc autosort faoi dháta 6

nótaí: Sa chód thuas, sórtálfar an dáta a iontráladh go huathoibríoch i gcolún A, is féidir leat athrú A1 agus A2 chuig do chealla féin de réir mar is gá duit.

3. As seo amach, nuair a iontrálfaidh tú an dáta i gcolún A, sórtálfar an dáta ag dul suas go huathoibríoch.

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello,This is a great tool. thank you. How can i apply this to multiple columns in the same tab? Could i apply it to restart sorting by date in a new cell of the same column? Would i just repaste the VBA code into the same window?
Thank you.
This comment was minimized by the moderator on the site
Hello Noname9,How are you? To achieve your goal by using VBA code is beyond my reach. But I do know how to use formulas to do the trick.Suppose we have two columns of dates, say A2:B7. How to sort these dates into a new column? Please do as follows.
First, we need to combine the two columns of dates into one column. Copy and paste the formula =INDEX($A$2:$B$7,INT((ROWS(D$2:D2)-1)/2)+1,MOD(ROWS(D$2:D2)-1,2)+1) into cell D2. And drag the fill handle down to combine all dates. Please see screenshot 1.
Then, we will sort the combined dates. Copy and paste the formula =INDEX($D$2:$D$13,MATCH(ROWS($D$2:D2),COUNTIF($D$2:$D$13,"<="&$D$2:$D$13),0)) into F2. And drag the fill handle down to sort all dates. Please see screenshot 2.
Hope it will help. Have a nice day.Sincerely,Mandy
This comment was minimized by the moderator on the site
Hello,What if i want to do this to multiple columns or even have anew start point in the same column? Do i just do a break and recopy the VBA code in that same window?
Thank you.
This comment was minimized by the moderator on the site
That VBA code is solid gold! Thank you! :-)
This comment was minimized by the moderator on the site
With the VBA code, I have copy and pasted the above but wish for the dates in column F to be the values by which the data is sorted. I've changed the range values to F2 and F3500 (the size of the spreadsheet where row 1 is titles), but it still sorts by the dates in column A. Can somebody help me please?
This comment was minimized by the moderator on the site
Hello, Ross,
When applying the code to column F, you should change some references to your need as below code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
On Error Resume Next
If Application.Intersect(Target, Application.Columns(6)) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
Range("F1").Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Is there a particular formula to keep the cells following the sorted date? It would be nice to organize by date but keep the entire row of information. Any help would be much appreciated.
This comment was minimized by the moderator on the site
I mad a checkbook register and it works but I want to figure out how to make my entry’s to go into date order. Any help would be appreciated. I’m still learning excel.
This comment was minimized by the moderator on the site
In addition to the duplicate dates, is there also a way to include multiple columns of data when it sorts? I need it to include multiple columns and sort them all together with the expiration dates.
This comment was minimized by the moderator on the site
how can I do this same sorting calculation but from newest date to oldest? Currently it is Oldest to Newest. Flipping the < sign isn't enough and beyond that I don't have a strong enough understanding of what it is doing. Also I think what may be happening is excel automatically works top to bottom causing difficulties.
This comment was minimized by the moderator on the site
Hello, Bo,

To auto sort the date from newest to oldest, you just need to change the <= to >= in the above formula as follows:
=INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,">="&$A$2:$A$15),0))
After inserting this formula, please remember to press Ctrl + Shift + Enter keys together to get the correct result.
Please try it.
This comment was minimized by the moderator on the site
What if there is a duplicate date in the list? And I want both numbers to show up.
This comment was minimized by the moderator on the site
Hello, Ryan,

To sort the date with duplicate ones, you should apply the following formula:

=IFERROR(INDEX($A$2:$A$11,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$11,"<="&$A$2:$A$11),0)),IF(ROWS($A$2:A2)<ROWS($A$2:$A$11),B3,""))

Please remember to press Shift + Ctrl + Enter keys together.

Hope it can help you, thank you!
This comment was minimized by the moderator on the site
Awesome :) Working fine
This comment was minimized by the moderator on the site
U forgot to mention the formula is array and you need to ctrl+Shift+ enter. Luckily you had a screenshot or your page would be a waste of cyberspace
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations