Excel VBA rowheigt 范围内的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16547330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA rowheigt from value in range
提问by fab_ulus
I have an Excel-Sheet with values in column D. I would like to set the row height in relation to the value of cell D of each row. Values in D are small %-values like 0.0593 %, except of the first (D4 = 31 %) and last (D92 = 40 %)
我有一个 Excel 表格,其中 D 列中有值。我想设置与每行单元格 D 值相关的行高。除了第一个 (D4 = 31 %) 和最后一个 (D92 = 40 %) 之外,D 中的值是小的百分比值,例如 0.0593 %
To get the small values at a reasonable height I'd like to multiply them with 10'000 - but there comes the problem with the 409 max height.
为了在合理的高度获得较小的值,我想将它们乘以 10'000 - 但是 409 的最大高度存在问题。
I have a script that works until it comes to the high values so I tried a if formula. But to be frankly: I have no Idea what I am doing here... I copied it together.
我有一个脚本,直到它达到高值为止,所以我尝试了一个 if 公式。但坦率地说:我不知道我在这里做什么......我一起复制了它。
So the problems: working only in the range of D5-D91 and if a value should go over 409 give him something like 15px.
所以问题是:只在 D5-D91 范围内工作,如果一个值应该超过 409,给他类似 15px 的东西。
Thanx for your Help!
感谢您的帮助!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
For i = 4 To Cells(Rows.Count, 1).End(xlUp).Row - 1
With Cells(i, 4)
If .Cells(i, 4).Value * 10000 > 409 Then
Rows(i).RowHeight = 12
Else
Rows(i).RowHeight = Cells(i, 4).Value * 10000
End If
End With
Next i
End Sub
回答by Santosh
Copy the below code to any standard module & Run. You may have to tweak the code as per your requirement.
将以下代码复制到任何标准模块并运行。您可能需要根据您的要求调整代码。
Sub sample()
Dim i As Long
For i = 4 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 4).Value * 10000 > 409 Then
Rows(i).RowHeight = 12
Else
Rows(i).RowHeight = Cells(i, 4).Value * 10000
End If
Next
End Sub
回答by fab_ulus
Sub sample()
Dim i As Long
For i = 4 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 4).Value * 100000 > 409 Then
Rows(i).RowHeight = 20
ElseIf Cells(i, 4).Value * 100000 < 10 Then
Rows(i).RowHeight = 12
Else
Rows(i).RowHeight = Cells(i, 4).Value * 100000
End If
Next
End Sub