日记首页
|
列表
|
添加日记
|
管理登陆
标题:用VBA 删除指定列名的列
<P> <TABLE style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); FONT-STYLE: normal; TEXT-INDENT: 0px; WIDTH: 757px; BORDER-COLLAPSE: collapse; FONT-FAMILY: Tahoma, 'Microsoft Yahei', Simsun; WHITE-SPACE: normal; ORPHANS: 2; EMPTY-CELLS: show; TABLE-LAYOUT: fixed; LETTER-SPACING: normal; COLOR: rgb(68,68,68); FONT-SIZE: 12px; FONT-WEIGHT: 400; WORD-SPACING: 0px; overflow-wrap: break-word; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial" cellSpacing=0 cellPadding=0> <TBODY style="overflow-wrap: break-word"> <TR style="overflow-wrap: break-word"> <TD style="FONT-SIZE: 14px; overflow-wrap: break-word" id=postmessage_7382951 class=t_f>sub test11<BR style="overflow-wrap: break-word">for j = Cells(Rows.Count, 1).End(xlUp).Row to 1 step -1<BR style="overflow-wrap: break-word">if cells(1,j)="列名" then<BR style="overflow-wrap: break-word">columns(j).delete<BR style="overflow-wrap: break-word">end if<SPAN> </SPAN><BR style="overflow-wrap: break-word">next<BR style="overflow-wrap: break-word">end sub</TD></TR></TBODY></TABLE></P> <P> <HR> </P> <P>实例,运用在《查询》中<BR>Sub 删除指定列名列()<BR>For j = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1<BR>If Cells(1, j) = "剩余课时" Then<BR>Columns(j).Delete<BR>End If<BR>Next</P> <P>For k = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1<BR>If Cells(1, k) = "结余" Then<BR>Columns(k).Delete<BR>End If<BR>Next</P> <P>For l = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1<BR>If Cells(1, l) = "次数" Then<BR>Columns(l).Delete<BR>End If<BR>Next</P> <P>End Sub</P>