仅显示确定的数据范围

我想向用户显示某个分离的工作表上存在的信息,只要他点击一个button。

我可以设置Excel“去”到该工作表的起始行,但我找不到一种方法来隐藏所有其他的东西。

有没有这方面的一些方法,或者我必须隐藏所有的行和列?

将用户窗体插入到工作簿的VB项目中。

将一个ListBox控件添加到用户窗体。

然后在UserForm_Activate事件代码中执行如下代码:

 Private Sub UserForm_Activate() Dim tbl As Range Set tbl = Range("B2:E7") '## Change this to capture the rang you need ' Me.Caption = "Displaying data from " & _ ActiveSheet.Name & "!" & tbl.Address With ListBox1 .ColumnHeads = False .ColumnCount = tbl.Columns.Count .RowSource = tbl.Address End With End Sub 

这给出了范围内未格式化的数据:

链接到userform的表的屏幕截图

要将范围导出为图像,您可以在用户窗体而不是一个列表框中创build一个图像。 那么这应该足以让你开始。

用户窗体中的图像的屏幕截图

正如你可以从这个截图看到的,图像可能并不总是非常清晰。 另外,如果你正在处理大量的单元格,图像可能不适合你的用户表单等。我将留下计算这部分你:)

 Private Sub UserForm_Activate() Dim tbl As Range Dim imgPath As String Set tbl = Range("B2:E7") '## Change this to capture the rang you need ' imgPath = Export_Range_Images(tbl) Caption = "Displaying data from " & _ ActiveSheet.Name & "!" & tbl.Address With Image1 If Not imgPath = vbNullString Then .Picture = LoadPicture(imgPath) .PictureSizeMode = fmPictureSizeModeClip .PictureAlignment = 2 'Center .PictureTiling = False .SpecialEffect = 2 'Sunken End If End With End Sub Function Export_Range_Images(rng As Range) As String '## Modified by David Zemens with ' credit to: _ ' http://vbadud.blogspot.com/2010/06/how-to-save-excel-range-as-image-using.html ##' Dim ocht As Object Dim srs As Series rng.CopyPicture xlScreen, xlPicture ActiveSheet.Paste Set ocht = ActiveSheet.Shapes.AddChart For Each srs In ocht.Chart.SeriesCollection srs.Delete Next '## Modify this line as needed ##' fname = "C:\users\david_zemens\desktop\picture.jpg" On Error Resume Next Kill fname On Error GoTo 0 ocht.Width = rng.Width ocht.Height = rng.Height ocht.Chart.Paste ocht.Chart.Export Filename:=fname, FilterName:="JPG" Application.DisplayAlerts = False ocht.Delete Application.DisplayAlerts = True Set ocht = Nothing Export_Range_Images = fname End Function 

如果您record a macro并手动隐藏一些列和行,代码将会为您生成,您将看到如何完成。