VBA如何实现EXCEL冻结窗格并获取行号列号。本次对冻结窗格的三种(冻结窗格、冻结首行、冻结首列)情况进行了VBA编程。
工具/原料
电脑
win10系统
Excel2016
方法/步骤
1、冻结窗格的三种(冻结窗格、冻结首行、冻结首列)
2、冻结窗格的三种(冻结窗格、冻结首行、冻结首列)代码如果Sub冻结窗格()Activ娣定撰钠eWindow.Fr髫潋啜缅eezePanes=TrueMsgBox"冻结单元格地址为:"&Replace(ActiveSheet.Cells(ActiveWindow.SplitRow+1,ActiveWindow.SplitColumn+1).Address,"$","")EndSubSub冻结首行窗格()ActiveWindow.SplitColumn=0ActiveWindow.SplitRow=1ActiveWindow.FreezePanes=TrueMsgBox"冻结的为第"&ActiveWindow.SplitRow&"行"EndSubSub冻结首列窗格()WithActiveWindow.SplitColumn=1.SplitRow=0EndWithActiveWindow.FreezePanes=TrueMsgBox"冻结的为第:"&ActiveWindow.SplitColumn&"列"EndSubSub取消冻结窗格()WithActiveWindow.SplitColumn=0.SplitRow=0EndWithActiveWindow.FreezePanes=FalseEndSubSub冻结窗格地址()IfActiveWindow.FreezePanesThenMsgBox"冻结单元格地址为:"&Replace(ActiveSheet.Cells(ActiveWindow.SplitRow+1,ActiveWindow.SplitColumn+1).Address,"$","")ElseMsgBox"未冻结单元格!"EndIfEndSub
3、必须启用宏:https://jingyan.baidu.com/articl娣定撰钠e/f0062228d512adbad3f0c895.html