Skip to main content

Conas gach líne bhán a scriosadh nó an chéad líne i gcill in Excel amháin?

D’fhéadfá leabhar oibre a fháil le línte iolracha ag meascadh le bearnaí i gcealla. Conas na línte bána seo a scriosadh i gcealla? Agus cad faoi ach an chéad líne a scriosadh? Cuideoidh an t-alt seo leat déileáil leis céim ar chéim.

Scrios gach líne bhán i gcealla le cód VBA
Scrios ach an chéad líne i gcealla le cód VBA


Scrios gach líne bhán i gcealla le cód VBA

Mar a thaispeántar sa screenshot thíos, chun gach líne bán sna cealla a scriosadh, is féidir leat an cód VBA seo a leanas a rith chun é a dhéanamh.

1. Brúigh an Eile + F11 eochracha ar do mhéarchlár, ansin osclaíonn sé a Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Sa Microsoft Visual Basic d’Fheidhmchláir fuinneog, cliceáil Ionsáigh > Modúil. Ansin cóipeáil agus greamaigh an cód VBA thíos sa Modúil fhuinneog.

Cód VBA: Scrios gach líne bhán i gcealla

Sub DoubleReturn()
Dim xRng As Range, xCell As Range
Dim I As Integer
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
On Error Resume Next
For Each xCell In xRng
  For I = 1 To Len(xCell) - Len(WorksheetFunction.Substitute(xCell, Chr(10), ""))
   xCell = Replace(xCell, Chr(10) + Chr(10), Chr(10))
  Next
Next
End Sub

3. Brúigh an F5 eochair chun an cód a rith. Ansin roghnaigh na cealla le línte bán a scriosfaidh tú sa Kutools le haghaidh Excel bosca dialóige. Agus ar deireadh cliceáil ar an OK cnaipe.

Ansin is féidir leat a fheiceáil go scriostar na línte bán go léir ó chealla sonraithe mar a thaispeántar an scáileán thíos. Tá na téacsanna suite i línte éagsúla fós.


Scrios ach an chéad líne i gcealla le cód VBA

Mar a thaispeántar sa screenshot thíos, chun an chéad líne a scriosadh i gcill A2 agus A3, is féidir leis an gcód VBA seo a leanas cabhrú leat.

1. Brúigh an Eile + F11 eochracha a oscailt Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Sa Microsoft Visual Basic d’Fheidhmchláir fuinneog, cliceáil Ionsáigh > Modúil. Ansin cóipeáil agus greamaigh an cód VBA thíos sa Modúil fhuinneog.

Cód VBA: Scrios ach an chéad líne i gcealla

Option Explicit
Sub RemoveFirstLine(ByRef Target As Range)
    Dim xCell As Range
    For Each xCell In Target.Cells
        xCell.Value = Right(xCell.Value, Len(xCell.Value) - InStr(1, xCell.Value, vbLf))
    Next
End Sub

Sub StartRemove()
Dim xRng As Range
   On Error Resume Next
   Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
   If xRng Is Nothing Then Exit Sub
   On Error Resume Next
   RemoveFirstLine xRng
End Sub

3. Brúigh an F5 eochair chun an cód a rith. Sa popping suas Kutools le haghaidh Excel bosca dialóige, roghnaigh le do thoil na cealla is gá duit a scriosadh ach an chéad líne, agus ansin cliceáil ar an OK cnaipe.

Ansin feiceann tú go ndéantar na chéad línte uile a scriosadh ó chealla sonraithe mar atá thíos an pictiúr a thaispeántar.


Airteagal gaolmhar:

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 (8)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
This Works it removed my all lines but the only issue is it is taking so much time to run for a single cell and i have big data with me to do it and i think it is gonna take tooo much time for that
This comment was minimized by the moderator on the site
Hi Tanveer Khan,
The code runs at normal speed on my side. Can you tell me which Excel version are you using?
This comment was minimized by the moderator on the site
This is my first VBA, I have only got up to your first step and it has solved my problem, so far. I have printed your instructions for future reference. So far I am wrapt. Fabulous instruction too, thank you for your quality skills and detailing them.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Jeg forstår desværre ikke et kvæk af ovenstående. Findes der ikke en nem og ligetil måde at fjerne tomme linier i Exell? Helst uden koder og andet mystisk!

Med venlig hilsen
Lene
This comment was minimized by the moderator on the site
Hello,
If you don't want to keep the original texts in different lines in cells, you can apply the following methods to get it done.
1. Use the Find & Replace feature:
Press the Ctrl + H keys. In the opening Find and Replace dialog box, click to activate the Find what box. Hold down the Alt key while typing 010 on the numeric keypad. Keep the Replace with box empty, click the Replace All button. But all the texts is concentrated on the same line.
2. Use the following formula in a helper column:
=SUBSTITUTE(A1, CONCATENATE(CHAR(13),CHAR(10),CHAR(13),CHAR(10)),CONCATENATE(CHAR(13),CHAR(10)))
where A1 is the cell you want to process.
This comment was minimized by the moderator on the site
Do you know how to adapt this to remove the last line instead of the first line, please? TIA
This comment was minimized by the moderator on the site
Hi,
this works awesome. How can I adjust the code to remove only the lines, not starting with numeric characters?

Thanks and best,
Jack
This comment was minimized by the moderator on the site
Hi Jack,
Sorry can't help you with that yet. Thank you for your comment.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations