Skip to main content

Conas luach na cille a athrú trí chliceáil ar an gcill?

An féidir linn luach cille a athrú trí chliceáil ar chill in Excel? Mar shampla, nuair a chliceálann tú cill shonrach A1, an chéad uair, taispeánann sé téacs “Excel”, má chliceálann tú an A1 arís, taispeántar téacs “Word”, agus taispeántar téacs “Outlook” nuair a chliceálann tú air seo cill sa tríú huair. Sa chás seo, beidh an luach i gcill A1 athfhillteach ó “Excel” go “Word” go “Outlook” go “Excel” …… mar a thaispeántar ar an scáileán a leanas:

athraigh doc luach trí chliceáil 1

Athraigh luach cille trí chliceáil ar chill le cód VBA


mboilgeog cheart gorm saighead Athraigh luach cille trí chliceáil ar chill le cód VBA

Chun an tasc seo a chríochnú in Excel, d’fhéadfadh an cód VBA seo a leanas cabhrú leat, déan mar a leanas le do thoil:

1. Cliceáil ar dheis ar an táb bileog ar mhaith leat luach cille a athrú trí chliceáil ar, agus roghnaigh Féach an cód ón roghchlár comhthéacs, agus san oscailt Microsoft Visual Basic d’Fheidhmchláir an cód seo a leanas a fhuinneogú, a chóipeáil agus a ghreamú isteach sa Mhodúl bán:

Cód VBA: Athraigh luach cille trí chliceáil ar chill:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'Updateby Extendoffice
  Application.EnableEvents = False
  With Target
  If .Address = Range("A1").Address Then
    Select Case .Value
      Case "Excel"
        .Value = "Word"
      Case "Word"
        .Value = "Outlook"
      Case "Outlook"
        .Value = "Excel"
      Case Else
        .Value = "Word"
    End Select
  End If
  End With
  Range("A2").Select
  Application.EnableEvents = True
End Sub

athraigh doc luach trí chliceáil 2

nótaí: Sa chód thuas, A1 an cill inar mian leat luach a athrú trí chliceáil, “Excel","focal","Outlook"Is iad na luachanna cille is mian leat a thaispeáint arís agus arís eile, is féidir leat iad a athrú de réir do riachtanas.

2. Tar éis duit an cód a ghreamú, ansin sábháil an cód agus dún an fhuinneog. Anois, nuair a chliceálann tú an chill A1 den chéad uair, taispeántar an téacs “Excel” ag an am céanna, cliceáil arís é, tá an téacs “Word” le feiceáil, taispeántar an téacs “Outlook” má chliceálann tú air an tríú huair, féach ar an scáileán:

athraigh doc luach trí chliceáil 1


Earraí níos gaolmhara:

Conas sonraí a scagadh ach trí ábhar cille a chliceáil in Excel?

Conas sonraí colún a shórtáil trí chliceáil ar cheanntásc in Excel?

Uirlisí Táirgiúlachta Oifige is Fearr

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 for Excel, agus Éifeachtúlacht Taithí Cosúil Riamh Roimhe. Kutools for Excel Tairiscintí os cionn 300 Ardghné chun Táirgiúlacht a Mhéadú agus Am a Shábháil.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

cluaisín kte 201905


Office Tab Tugann sé comhéadan Tabbed chuig Oifig, agus Déan do chuid Oibre 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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is great information, thanks for everyone's input! Is there away to apply this same type of approach with a lookup or index\match value?

For example, if I click on a value in A1, can the VBA be configured to index that value in another worksheet column, and display a matched value in B1? Thank you again!
This comment was minimized by the moderator on the site
I am trying to apply this to an entire column of individual cells, not just one cell. Is this possible? When I change the range from "A1" to "A1:A100" nothing happens when I click the cells in that range.
This comment was minimized by the moderator on the site
This is the final code that worked for me.  I use it to check a cell when an item is completed.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.EnableEvents = False
    With Target
      Dim KeyCells As Range
      Set KeyCells = Range("D6:D8000")
      If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        Select Case .Value
          Case "ü"
            .Value = ""
          Case ""
            .Value = "ü"
        End Select
      End If
    End With
  Application.EnableEvents = True
End Sub
This comment was minimized by the moderator on the site
You can do that by declaring the range you want to have as KeyCells and than put that into the Application.Intersection Method. This will let you change the Value of your choice from all the cells. Worked for me but i am bad at explaining ^^


Application.EnableEvents = False
With Target


Dim KeyCells as Range

Set KeyCells = Range("A1:A100")

If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then

Select Case .Value

...
This comment was minimized by the moderator on the site
You can do that by declaring the range you want to have as KeyCells and than put that into the Application.Intersection Method. This will let you change the Value of your choice from all the cells. Worked for me but i am bad at explaining ^^

Dim KeyCells as Range

Set KeyCells = Range("A1:A100")

If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then

Select Case .Value

...
This comment was minimized by the moderator on the site
I did it but i will not tell anyone MUWAHAHAHAHAHAHAHAHAHA
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations