Excel精英培训网

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

[已解决]有以下几个圆形 有没有办法用VBA让他们整齐的排成一行在绿色区

[复制链接]
发表于 2015-10-22 21:23 | 显示全部楼层 |阅读模式
本帖最后由 tzjx200521 于 2015-10-23 18:49 编辑

有以下几个圆形 有没有办法用VBA让他们整齐的排成一行在绿色区
最佳答案
2015-10-23 09:53
Sub test()
    Dim Rng, L, W, H, moveH, x

    Set Rng = Range("a1:h6")    '颜色区域
    L = Rng.Left
    W = Rng.Width / chartCount
    H = W    '为得到正圆
    moveH = (Rng.Height - H) / 2 '偏移高度

    For Each x In ActiveSheet.Shapes
        If x.Type = 1 Then
            x.Left = L: L = L + W
            x.Top = Rng.Top + moveH
            x.Width = W
            x.Height = H
        End If
    Next
End Sub

'求自选图形的个数(如果全是自选图形,可用 ActiveSheet.Shapes.Count )
Function chartCount() As Integer
    Dim x, s
    For Each x In ActiveSheet.Shapes
        If x.Type = 1 Then s = s + 1
    Next
    chartCount = s
End Function

排成一行.rar (15.79 KB, 下载次数: 10)

新建 Microsoft Excel 工作表.rar

8.05 KB, 下载次数: 5

发表于 2015-10-23 09:53 | 显示全部楼层    本楼为最佳答案   
Sub test()
    Dim Rng, L, W, H, moveH, x

    Set Rng = Range("a1:h6")    '颜色区域
    L = Rng.Left
    W = Rng.Width / chartCount
    H = W    '为得到正圆
    moveH = (Rng.Height - H) / 2 '偏移高度

    For Each x In ActiveSheet.Shapes
        If x.Type = 1 Then
            x.Left = L: L = L + W
            x.Top = Rng.Top + moveH
            x.Width = W
            x.Height = H
        End If
    Next
End Sub

'求自选图形的个数(如果全是自选图形,可用 ActiveSheet.Shapes.Count )
Function chartCount() As Integer
    Dim x, s
    For Each x In ActiveSheet.Shapes
        If x.Type = 1 Then s = s + 1
    Next
    chartCount = s
End Function

排成一行.rar (15.79 KB, 下载次数: 10)
回复

使用道具 举报

 楼主| 发表于 2015-10-23 18:48 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 18:10 , Processed in 0.618907 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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