Excel宏:如何更改所有行高,但是如果cell.value = bold使单元格高度更大? [英] Excel macro: how do I change all row heights, BUT if cell.value = bold make the cell height bigger?

查看:206
本文介绍了Excel宏:如何更改所有行高,但是如果cell.value = bold使单元格高度更大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一大串使用粗体和缩进进行格式化的数据(列B)。粗体单元格包含标题/类别名称,缩进的单元格值是子类别。



行高已经满了。它应该是10.5的一切,和粗细胞/行 15.我可以改变一切10.5,但是我需要花相当多的时间滚动列表修改大胆的行高。我已经使用了格式画家,但是这是一个很长的列表,我不想在这个过程中花费太多的时间。而现在我知道我需要这样做到另外30个文件。

有没有人有更快的方式做到这一点?

解决方案
Dim targetCell As Range

Set targetRange = Range(B:B)
对于每个targetCell在targetRange中
如果不是IsEmpty(targetCell)则
如果是targetCell。 Font.Bold Then
targetCell.RowHeight = 15
ElseIf targetCell.Font.Superscript Then
targetCell.RowHeight = 12.75
else
targetCell.RowHeight = 10.5
End If
End If
Next targetCell
End Sub

您可能想将 Range(B:B)更改为类似于 Table1.Range(B1:B255)


I'm working on a long list of data (Column B) that has been formatted using bold and indents. The bold cells contain the titles/category names and the indented cell values are the subcategories.

The row heights are all over the place. It should have been 10.5 for everything, and the bold cells/rows 15. I can change everything to 10.5, but then I need to spend quite a bit of time scrolling through the list amending the bold row heights. I've used the format painter but it's a long list and I didn't want to spend so much time on this part of the process. And now I know that I'll need to do this to another 30 documents.

Does anyone have a quicker way of doing this?

解决方案

Sub setHeights()
Dim targetRange As Range
Dim targetCell As Range

    Set targetRange = Range("B:B")
    For Each targetCell In targetRange
        If Not IsEmpty(targetCell) Then
            If targetCell.Font.Bold Then
                targetCell.RowHeight = 15
            ElseIf targetCell.Font.Superscript Then
                targetCell.RowHeight = 12.75
            Else
                targetCell.RowHeight = 10.5
            End If
        End If
    Next targetCell
End Sub

You might want to change Range("B:B") to something like Table1.Range("B1:B255")

这篇关于Excel宏:如何更改所有行高,但是如果cell.value = bold使单元格高度更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆