程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> vba 自動獲取表的行 代碼

vba 自動獲取表的行 代碼

編輯:VB綜合教程
 

x = Range("b65536").End(xlUp).Row
當前表的行數

工作表行和列的操作
[示例01]隱藏行
Sub HideRow()
Dim iRow As Long
MsgBox "隱藏當前單元格所在的行"
iRow = ActiveCell.Row
ActiveSheet.Rows(iRow).Hidden = True
MsgBox "取消隱藏"
ActiveSheet.Rows(iRow).Hidden = False
End Sub

[示例02]隱藏列
Sub HideColumn()
Dim iColumn As Long
MsgBox "隱藏當前單元格所在列"
iColumn = ActiveCell.Column
ActiveSheet.Columns(iColumn).Hidden = True
MsgBox "取消隱藏"
ActiveSheet.Columns(iColumn).Hidden = False
End Sub

[示例03]插入行
Sub InsertRow()
Dim rRow As Long
MsgBox "在當前單元格上方插入一行"
rRow = Selection.Row
ActiveSheet.Rows(rRow).Insert
End Sub

[示例04]插入列
Sub InsertColumn()
Dim cColumn As Long
MsgBox "在當前單元格所在行的左邊插入一行"
cColumn = Selection.Column
ActiveSheet.Columns(cColumn).Insert
End Sub

[示例05]插入多行
Sub InsertManyRow()
MsgBox "在當前單元格所在行上方插入三行"
Dim rRow As Long, i As Long
For i = 1 To 3
rRow = Selection.Row
ActiveSheet.Rows(rRow).Insert
Next i
End Sub

[示例06]設置行高
Sub SetRowHeight()
MsgBox "將當前單元格所在的行高設置為25"
Dim rRow As Long, iRow As Long
rRow = ActiveCell.Row
iRow = ActiveSheet.Rows(rRow).RowHeight
ActiveSheet.Rows(rRow).RowHeight = 25
MsgBox "恢復到原來的行高"
ActiveSheet.Rows(rRow).RowHeight = iRow
End Sub

[示例07]設置列寬
Sub SetColumnWidth()
MsgBox "將當前單元格所在列的列寬設置為20"
Dim cColumn As Long, iColumn As Long
cColumn = ActiveCell.Column
iColumn = ActiveSheet.Columns(cColumn).ColumnWidth
ActiveSheet.Columns(cColumn).ColumnWidth = 20
MsgBox "恢復至原來的列寬"
ActiveSheet.Columns(cColumn).ColumnWidth = iColumn
End Sub

[示例08]恢復行高列寬至標准值
Sub ReSetRowHeightAndColumnWidth()
MsgBox "將當前單元格所在的行高和列寬恢復為標准值"
Selection.UseStandardHeight = True
Selection.UseStandardWidth = True
End Sub
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved