Dropdown daim ntawv nrog ntau xaiv

Daim ntawv teev npe nco-down classic hauv daim ntawv Excel yog qhov zoo, tab sis nws tsuas yog tso cai rau koj xaiv ib qho kev xaiv los ntawm cov teeb tsa tau nthuav tawm. Qee zaum qhov no yog qhov koj xav tau, tab sis muaj cov xwm txheej uas tus neeg siv yuav tsum muaj peev xwm xaiv tau ib co cov ntsiab lus los ntawm cov npe.

Cia peb saib ob peb qhov kev coj ua ntawm xws li ntau daim ntawv xaiv.

Kev xaiv 1. Kab rov tav

Tus neeg siv xaiv cov khoom los ntawm cov npe drop-down ib qho los ntawm ib qho, thiab lawv tshwm sim rau sab xis ntawm lub xov tooj hloov pauv, cia li tau teev nyob rau kab rov tav:

Cov npe poob hauv cov hlwb C2:C5 hauv qhov piv txwv no yog tsim los ntawm tus qauv, piv txwv li

  1. xaiv cov hlwb C2: C5
  2. tab or menu Cov ntaub ntawv xaiv ib pab neeg Cov Ntaub Ntawv Kev Siv Tau
  3. nyob rau hauv lub qhov rais uas qhib, xaiv ib qho kev xaiv daim ntawv teev thiab qhia raws li qhov ntau Tau qhov twg los cell nrog cov ntaub ntawv los ntawm cov npe A1:A8

Tom qab ntawd koj yuav tsum tau ntxiv ib qho macro rau daim ntawv module, uas yuav ua tag nrho cov haujlwm tseem ceeb, piv txwv li ntxiv cov nqi xaiv rau sab xis ntawm lub hlwb ntsuab. Txhawm rau ua qhov no, right-click ntawm nplooj ntawv tab nrog cov npe poob thiab xaiv cov lus txib Qhov chaws code. Muab cov cai hauv qab no tso rau hauv Visual Basic editor qhov rai uas qhib:

Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next If Not Intersect(Target, Range("C2:C5")) Tsis muaj dab tsi Thiab Target.Cells.Count = 1 Ces Application.EnableEvents = False Yog Len(Target.Offset (0, 1)) = 0 Then Target.Offset(0, 1) = Target Else Target.End(xlToRight).Offset(0, 1) = Target End Yog Target.ClearContents Application.EnableEvents = True End Yog End Sub  

Yog tias tsim nyog, hloov qhov rhiab ntau ntawm cov npe poob qis C2: C5 hauv kab thib ob ntawm cov cai no nrog koj tus kheej.

Kev xaiv 2. Vertical

Ib yam li nyob rau hauv lub dhau los version, tab sis cov tshiab xaiv qhov tseem ceeb tsis ntxiv rau sab xis, tab sis mus rau hauv qab:

Nws yog ua raws nraim li txoj kev, tab sis tus handler macro code hloov me ntsis:

Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next If Not Intersect(Target, Range("C2:F2")) Tsis muaj dab tsi Thiab Target.Cells.Count = 1 Ces Application.EnableEvents = False Yog Len(Target.Offset (1, 0)) = 0 Then Target.Offset(1, 0) = Target Else Target.End(xlDown).Offset(1, 0) = Target End Yog Target.ClearContents Application.EnableEvents = True End Yog End Sub  

Ib zaug ntxiv, yog tias tsim nyog, hloov qhov rhiab ntau ntawm C2: F2 cov npe nco-down nrog koj tus kheej hauv kab thib ob ntawm cov cai no.

Kev xaiv 3. Nrog tsub zuj zuj hauv tib lub cell

Nyob rau hauv qhov kev xaiv no, lub tsub zuj zuj tshwm sim nyob rau hauv tib lub xov tooj ntawm tes uas lub drop-down daim ntawv teev nyob rau hauv. Cov ntsiab lus xaiv raug cais los ntawm ib tus cwj pwm muab (piv txwv li, tus lej cim):

Cov npe poob hauv cov hlwb ntsuab yog tsim nyob rau hauv ib txoj hauv kev ua tiav, zoo li hauv txoj kev dhau los. Tag nrho cov haujlwm tau ua tiav, dua, los ntawm macro hauv daim ntawv module:

Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next If Not Intersect(Target, Range("C2:C5")) Tsis muaj dab tsi Thiab Target.Cells.Count = 1 Ces Application.EnableEvents = False newVal = Target Application.Undo oldval = Target Yog Len(oldval) <> 0 Thiab oldval <> newVal Then Target = Target & "," & newVal Else Target = newVal End Yog Yog Len(newVal) = 0 Ces Target.ClearContents Application.EnableEvents = True End Yog End Sub  

Yog tias xav tau, koj tuaj yeem hloov tus cim cais (comma) hauv kab 9th ntawm cov lej nrog koj tus kheej (piv txwv li, ib qho chaw lossis semicolon).

  • Yuav ua li cas los tsim ib daim ntawv teev npe yooj yim hauv daim ntawv Excel
  • Daim ntawv teev npe nrog cov ntsiab lus
  • Daim ntawv teev npe nrog cov kev xaiv uas ploj lawm ntxiv
  • Dab tsi yog macro, siv lawv li cas, qhov twg los ntxig macro code hauv Visual Basic

Sau ntawv cia Ncua