我有一个查询数据库的Excel表 - 它返回的行数会波动。
当行数发生变化时,是否有人知道如何自动调整表格大小,以便整个表格始终适合屏幕?
答案 0 :(得分:1)
听起来好像你指的是缩放。对于这个方便的子目录,Chip Pearson的所有积分。
使用示例:call ZoomToRange(activesheet.cells(1,1).currentregion, true)
Sub ZoomToRange(ByVal ZoomThisRange As Range, _
ByVal PreserveRows As Boolean)
'http://www.cpearson.com/excel/zoom.htm
Dim Wind As Window
Set Wind = ActiveWindow
'
' Put the upper left cell of the range in the top-left of the screen.
'
Application.Goto ZoomThisRange(1, 1), True
With ZoomThisRange
If PreserveRows = True Then
.Resize(.Rows.Count, 1).Select
Else
.Resize(1, .Columns.Count).Select
End If
End With
With Wind
.Zoom = True
.VisibleRange(1, 1).Select
End With
End Sub