Excel精英培训网

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

有没有不选取,直接设置格式的办法

[复制链接]
发表于 2008-12-4 23:01 | 显示全部楼层 |阅读模式

我想对一定区域设置格式为文本、横居中、竖居中、宋体、常规、8号、加边框、着底色,但是选择后进行设置的,能否直接赋予格式?

我的代码如下,

Sub Macro3() '表头内容、格式处理
Application.ScreenUpdating = False
表头 = Array("编号", "年度", "拨付单位", "拨付对象", "分配金额", "本级配套", "拨付金额", "拨付时间", "备注", "区划简码")
    Sheets(Array(1, 2, 3)).Select   '"分配表", "分配明细表")).Select
    Rows("1:1").Select
    Selection.Clear
    Range("A1:J1").Select
    Selection.Value = 表头
    Selection.NumberFormatLocal = "@"
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
    End With
    With Selection.Font
        .Name = "宋体"
        .FontStyle = "常规"
        .Size = 9
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.249977111117893
        .PatternTintAndShade = 0
    End With
    Sheets(4).Select
    With Sheets(1)
        .Range("e1").Insert Shift:=xlToRight
        .Range("e1").Value = "上年结转"
    End With
    Sheets(4).Select
    Application.ScreenUpdating = True
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2008-12-4 23:15 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-24 14:05 , Processed in 0.180058 second(s), 4 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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