ZKX's LAB

vba 选择区域 地址出现在 excel vba如何引用当前选择的区域

2020-08-11知识13

excel中使用vba选择多个区域单元格,小编致力于为大家奉献最有效的经验,让大家能够解决掉问题,但是大家也都知道,每个人遇到的情况都是不一样的,大家在看小编经验的同时。在VBA中,编写代码使所选区域地址显示在状态栏,本篇经验将和大家分享【如何编写事件程序代码使所选区域地址显示于状态栏】。VBA判断选择区域 Sub DynamicRangeSelect()Dim i As Long,j As Integer,stp As BooleanDim curRowUsed As BooleanDim maxCol As Integer,firstRow As Integerstp=False '初始2113化变量stpi=1 '初始化变量imaxCol=2 '初始化最大列号'找出第一个5261非空行4102Do Until Range(\"B\"&i)<;>;\"i=i+1If i>;10 ThenMsgBox\"没有可被选择的数据Exit Sub '此句防止无数1653据导致死循环,可以根据实际情况调整此参数大小End IfLoopfirstRow=i '记住找到的第一个非空行i=i+1Do Until stp=TruecurRowUsed=FalseFor j=2 To 255If firstRow>;0 ThenIf Cells(i,j)<;>;\"\"ThencurRowUsed=TrueIf j>;maxCol Then maxCol=j '标记最大列号End IfEnd IfNext j'碰到全行空白则发出停止循环指令If curRowUsed=False Thenstp=Truei=i-1 '此时的i减1即为最大行号End IfIf stp=False Then i=i+1LoopRange(Cells(firstRow,2),Cells(i,maxCol)).Select '选择动态区域End Sub利用VBA在Excel中对选定区域进行绝对地址和相对地址装换。 把你的公式修改了一下.点一下按钮如果之前是相对引用,就变成绝对引用.再点一下,就变回原来的Private Sub CommandButton1_Click()Dim rng As Range,temp$For Each rng In UsedRange.SpecialCells(xlCellTypeFormulas)If InStr(rng.Formula,\"$\")Thentemp=Application.ConvertFormula(rng.Formula,xlA1,xlA1,xlRelative)If rng.HasArray Then rng.FormulaArray=temp Else rng.Formula=tempElsetemp=Application.ConvertFormula(rng.Formula,xlA1,xlA1,xlAbsolute)If rng.HasArray Then rng.FormulaArray=temp Else rng.Formula=tempEnd IfNextEnd Subexcel vba如何引用当前选择的区域 试试这段 Private Sub CommandButton1_Click()Dim rCurr As Range ActiveSheet.Cells().Interior.Color=-4142 Set rCurr=Selection Dim a As String a=rCurr.Address 。

#vba#sub#电子表格

随机阅读

qrcode
访问手机版