Yuav Ua Li Cas Tshem Tawm Vba Kab

Cov txheej txheem:

Yuav Ua Li Cas Tshem Tawm Vba Kab
Yuav Ua Li Cas Tshem Tawm Vba Kab

Video: Yuav Ua Li Cas Tshem Tawm Vba Kab

Video: Yuav Ua Li Cas Tshem Tawm Vba Kab
Video: Yuav Ua Li Cas Thiaj Tsis Hiav 2024, Hlis ntuj nqeg
Anonim

Tshem tawm VBA kab yog tus qauv thiab cov txheej txheem feem ntau siv los ntawm cov kws tsim tawm. Txawm li cas los xij, rau cov neeg siv qis dua, qhov kev ua haujlwm no yuav ua rau qee qhov nyuaj.

Yuav ua li cas tshem tawm vba kab
Yuav ua li cas tshem tawm vba kab

Cov Lus Qhia

Kauj ruam 1

Nco ntsoov tias koj nkag siab cov syntax rau cov kab lus txiav tawm siv qhov hais kom ua Delete. Yog li rau kab uas muaj cov cell nquag, qhov hais kom ua yuav zoo li ActiveCell. EntireRow. Delete, thiab qhov yuav tsum tau rho tawm tus lej ntawm cov kab yuav hloov nws mus rau Kab ("first_line_number: last_line_number"). Delete (rau Excel).

Kauj ruam 2

Siv cov ntawv cim zoo sib xws rau cov lus xaiv rho tawm kab hauv VBA, tab sis nrog cov kev xaiv siab. Txhawm rau ua qhov no, ua ntej ntawm txhua yam txhais tau cov haujlwm xav tau: Private Sub Delete line_Click (). Qhia meej rau daim ntawv thov uas xav tau Dim ea Ua Excel. Application thiab xaiv phau ntawv xav tau Dim ewb Raws li Excel. Workbook. Tom qab ntawv sau lub nplooj ntawm Dim ews Raws li Excel. Worksheet daim ntawv yuav tsum tau kho.

Kauj ruam 3

Hla ib kab thiab nkag rau Teeb XLAp = CreateObject (Chav Kawm: = "Excel. Application"). Teem qhov muab nkag rau ntawm cov kab hauv qab no: Teeb XLWb = XLAp. Workbooks. Qhib ("drive_name: 1.xls") Siv cov nqi hauv qab no: Teeb XLWs = XLWb. ActiveSheet.

Kauj ruam 4

Hla mus rau lwm txoj kab thiab sau tus nqi ntawm txoj haujlwm uas raug xaiv: XLWs. Rows (1). Rho tawm. Tseg cov ntawv kho: XLWb. Save. Tawm ntawm cov ntaub ntawv qhib: XLAp. Quit.

Kauj ruam 5

Hla kab txuas tom ntej thiab hloov cov qhob hloov nrog cov khoom cim xeeb: Teeb XLWs = Tsis muaj dab tsi. Rov ua dua cov lus txib rau txhua tus qhib sib txawv: Teeb XLWb = Tsis muaj dab tsi thiab thaum kawg kab kawg: Teeb XLAp = Tsis muaj dab tsi.

Kauj Ruam 6

Siv cov ntawv loj loj los ua cov haujlwm ntau dua kom lawb tawm cov kab tsis tseem ceeb hauv ib daim ntawv. Txhawm rau ua qhov no, tsim ib phau ntawv Excel ua haujlwm tshiab thiab nkag mus rau qhov tseem ceeb xav tau. Qhib cov "Service" menu ntawm lub toolbar sab sauv ntawm qhov program program thiab xaiv "Macro" yam khoom. Xaiv cov "Visual Basic Editor" sub-item thiab nthuav cov "Ntxig" cov zaub mov. Xaiv cov khoom "Module" thiab ntxig daim ntawv tsim. Rov qab rau cov ntawv qhia "Cuab yeej" thiab rov qab mus rau "Macro" yam khoom. Siv cov "Macros" sub-item thiab qhia kom meej cov kev tsim tshiab. Dlha macro los txhaj khawm Dhia.

Pom zoo: