Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1798|回复: 3

[已解决]新手菜鸟求打印代码修改

[复制链接]
发表于 2012-10-25 06:48 | 显示全部楼层 |阅读模式

  1. Sub 打印()

  2. If Sheets("Sheet2").[D15] = "" Then MsgBox "D15,不为空!": Exit Sub

  3. Dim c As Range

  4.     With Sheet1

  5.     Set c = .UsedRange.Find(Sheet1.[D15], , , 1)

  6.     If Not c Is Nothing Then

  7.         .PageSetup.PrintArea = .Range(.Cells(1, 1), .Cells(c.Row + 53, c.Column + 8)).Address

  8.         .PrintOut

  9.     End If

  10.     End With


  11.     End Sub
复制代码
我在Sheet2表设一个按钮打印
单元格D15不为空时打印
为空时不能打印
以上功能可实现
可是打印出来的不是我要的
我要的是Sheet2表的数据
不是Sheet1表的数据
对了 我的表 名称要是中文字 那要如何改
菜鸟不懂  打印 也是抓来的
请老师帮修改
谢谢
最佳答案
2012-10-25 07:27
  1. Sub 打印()

  2. If Sheets("Sheet2").[D15] = "" Then MsgBox "D15,不为空!": Exit Sub

  3. Dim c As Range

  4.     With Sheets("Sheet2")

  5.         Set c = .UsedRange.Find(.[D15], , , 1)
  6.    
  7.         If Not c Is Nothing Then
  8.    
  9.             .PageSetup.PrintArea = .Range(.Cells(1, 1), .Cells(c.Row + 53, c.Column + 8)).Address
  10.    
  11.             .PrintOut
  12.    
  13.         End If

  14.     End With

  15. End Sub
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-10-25 07:25 | 显示全部楼层
回复

使用道具 举报

发表于 2012-10-25 07:27 | 显示全部楼层    本楼为最佳答案   
  1. Sub 打印()

  2. If Sheets("Sheet2").[D15] = "" Then MsgBox "D15,不为空!": Exit Sub

  3. Dim c As Range

  4.     With Sheets("Sheet2")

  5.         Set c = .UsedRange.Find(.[D15], , , 1)
  6.    
  7.         If Not c Is Nothing Then
  8.    
  9.             .PageSetup.PrintArea = .Range(.Cells(1, 1), .Cells(c.Row + 53, c.Column + 8)).Address
  10.    
  11.             .PrintOut
  12.    
  13.         End If

  14.     End With

  15. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-10-29 08:58 | 显示全部楼层
hwc2ycy 发表于 2012-10-25 07:27

谢谢你~是我想要的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-27 04:22 , Processed in 0.303968 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表