|
楼主 |
发表于 2014-6-12 17:05
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 621107 于 2014-6-12 18:14 编辑
ythtdewo 发表于 2014-2-7 12:13
发现一个问题,想请教大家。
如果内容有上标的话,会出现算出来的高度不够的情况,应该怎么解决好呢?
你这个上标是怎么弄出来的.. 上传上来我试试,
我原来的帖子好像没办法编辑了 我修改了下代码 修复了代码中一个复制的问题 你再试试看行不行:
- Sub My_MergeCell_AutoHeight()
- Dim rh As Single, mw As Single
- Dim rng As Range, rrng As Range, n1%, n2%
- Dim aw As Single, rh1 As Single
- Dim m$, n$, k
- Dim ir1, ir2, ic1, ic2
- Dim mySheet As Worksheet
- Dim selectedA As Range
- Dim wrkSheet As Worksheet
-
- Application.ScreenUpdating = False
- Set mySheet = ActiveSheet
- On Error Resume Next
- Err.Number = 0
- Set selectedA = Application.Intersect(ActiveWindow.RangeSelection, mySheet.UsedRange)
- selectedA.Activate
- If Err.Number <> 0 Then
- g = MsgBox("请先选择需要'最合适行高'的行!", vbInformation)
- Return
- End If
- selectedA.EntireRow.AutoFit
- Set wrkSheet = ActiveWorkbook.Worksheets.Add
- For Each rrng In selectedA
- If rrng.Address <> rrng.MergeArea.Address Then
- If rrng.Address = rrng.MergeArea.Item(1).Address Then
-
- 'If (Application.Intersect(selectedA, rrng).Address <> rrng.Address) Then
- ' GoTo gotoNext
- 'End If
-
- Dim tempCell As Range
- Dim width As Double
- Dim tempcol
- width = 0
- For Each tempcol In rrng.MergeArea.Columns
- width = width + tempcol.ColumnWidth
- Next
- wrkSheet.Columns(1).WrapText = True
- wrkSheet.Columns(1).ColumnWidth = width
- wrkSheet.Columns(1).Font.Size = rrng.Font.Size
- rrng.Copy Destination:=wrkSheet.Cells(1, 1)
- 'wrkSheet.Cells(1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
- wrkSheet.Activate
- wrkSheet.Cells(1, 1).RowHeight = 0
- wrkSheet.Cells(1, 1).EntireRow.Activate
- wrkSheet.Cells(1, 1).EntireRow.AutoFit
- mySheet.Activate
- rrng.Activate
- If (rrng.RowHeight < wrkSheet.Cells(1, 1).RowHeight) Then
- Dim tempHeight As Double
- Dim tempCount As Integer
- tempHeight = wrkSheet.Cells(1, 1).RowHeight
- tempCount = rrng.MergeArea.Rows.Count
- For Each addHeightRow In rrng.MergeArea.Rows
-
- If (addHeightRow.RowHeight < tempHeight / tempCount) Then
- addHeightRow.RowHeight = tempHeight / tempCount
- End If
- tempHeight = tempHeight - addHeightRow.RowHeight
- tempCount = tempCount - 1
- Next
- End If
- End If
- End If
- Next
- Application.DisplayAlerts = False '删除工作表警告提示去消
- wrkSheet.Delete
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|