Sut i ddod o hyd i bennawd neu droedyn yn Excel?
Mae dod o hyd i werth penodol ac yna rhoi gwerth arall yn Excel yn ei le yn gyffredin yn ein gwaith beunyddiol, ond yn Excel, mae'r swyddogaeth Darganfod ac Amnewid yn gweithio'n dda mewn dewis, taflenni a llyfr gwaith, ond ni all ddod o hyd i bennawd a throedyn a'i ddisodli. Yn yr erthygl hon, rwy'n cyflwyno cod macro i ddarganfod a disodli gwerthoedd mewn pennawd a throedyn.
Dewch o hyd i VBA yn ei bennawd neu ei droedyn
Dewch o hyd i VBA yn ei bennawd neu ei droedyn
1. Galluogi'r ddalen rydych chi am ddod o hyd iddi a rhoi pennawd a throedyn yn ei lle, gwasgwch Alt + F11 allweddi i agor Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.
2. Cliciwch Mewnosod > Modiwlau, a'i gludo o dan god VBA i'r Modiwl. Gweler y screenshot:
VBA: Dewch o hyd i bennawd a throedyn a'i ailosod
Sub FnR_HF()
'UpdateByExtendoffice20160623
Dim xStr As String, xRep As String
'Const csTITLE As String = "Find and Replace"
On Error Resume Next
xStr = Application.InputBox("Replace what", "Kutools for Excel", , , , , 2)
If xStr = "" Then Exit Sub
xRep = Application.InputBox("With what", , "Kutools for Excel", , , , , 2)
With ActiveSheet.PageSetup
' Substitute Header/Footer values
.LeftHeader = Application.WorksheetFunction.Substitute(.LeftHeader, xStr, xRep)
.CenterHeader = Application.WorksheetFunction.Substitute(.CenterHeader, xStr, xRep)
.RightHeader = Application.WorksheetFunction.Substitute(.RightHeader, xStr, xRep)
.LeftFooter = Application.WorksheetFunction.Substitute(.LeftFooter, xStr, xRep)
.CenterFooter = Application.WorksheetFunction.Substitute(.CenterFooter, xStr, xRep)
.RightFooter = Application.WorksheetFunction.Substitute(.RightFooter, xStr, xRep)
End With
End Sub
3. Yna pwyswch F5 allwedd i redeg y cod, yna mae deialog yn galw allan i chi nodi'r testun rydych chi am ddod o hyd iddo. Gweler y screenshot:
4. Cliciwch OK, ac mae deialog arall yn galw allan i nodi'r testun rydych chi am ei ddisodli. Gweler y screenshot:
5. Cliciwch OK. Nawr y gwerthoedd “KTE” wedi eu disodli “Kutools ar gyfer Excel” mewn pennawd a throedyn.
Tip: Os ydych chi eisiau gweithio i'r llyfr gwaith cyfan, gallwch ei ddefnyddio o dan god macro.
Sub FnR_HF()
'UpdateByExtendoffice20171122
Dim I As Long
Dim xStr As String, xRep As String
'Const csTITLE As String = "Find and Replace"
On Error Resume Next
xStr = Application.InputBox("Replace what", "Kutools for Excel", , , , , 2)
If xStr = "" Then Exit Sub
xRep = Application.InputBox("With what", , "Kutools for Excel", , , , , 2)
For I = 1 To ActiveWorkbook.Sheets.Count
With Sheets(I).PageSetup
' Substitute Header/Footer values
.LeftHeader = Application.WorksheetFunction.Substitute(.LeftHeader, xStr, xRep)
.CenterHeader = Application.WorksheetFunction.Substitute(.CenterHeader, xStr, xRep)
.RightHeader = Application.WorksheetFunction.Substitute(.RightHeader, xStr, xRep)
.LeftFooter = Application.WorksheetFunction.Substitute(.LeftFooter, xStr, xRep)
.CenterFooter = Application.WorksheetFunction.Substitute(.CenterFooter, xStr, xRep)
.RightFooter = Application.WorksheetFunction.Substitute(.RightFooter, xStr, xRep)
End With
Next
End Sub
Offer Cynhyrchiant Swyddfa Gorau
Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser. Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...
Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer
- Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
- Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
- Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!