Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2021, 05:27 AM
eduzs eduzs is offline Retrieve row height merged cells Windows 10 Retrieve row height merged cells Office 2019
Expert
Retrieve row height merged cells
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default Retrieve row height merged cells

Original post was something like:
Retrieve rows height within a table with vertically merged cells, where the simple code below returns error 5991:
Quote:
Sub Test()


Dim oRow as Row
For Each oRow In Selection.Tables(1).Rows
Debug.Print oRow.Height
Next oRow
End Sub
__________________
Backup your original file before doing any modification.

Last edited by eduzs; 03-14-2021 at 03:13 PM.
Reply With Quote
  #2  
Old 03-14-2021, 02:18 PM
Guessed's Avatar
Guessed Guessed is offline Retrieve row height merged cells Windows 10 Retrieve row height merged cells Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The workaround would be to iterate through all the table cells. If you only wanted to pick one table cell per row it would be easiest to settle on the first cell in each row. Note that it might be useful to also know the cell height rule since rows that automatically adjust their heights will all return an undefined height (9999999)
Code:
Sub CheckRows()
  Dim aRow As Row, aCell As Cell, aTable As Table
  
  If Selection.Tables.Count > 0 Then
    Set aTable = Selection.Tables(1)
    If aTable.Uniform Then
      For Each aRow In aTable.Rows
        Debug.Print aRow.Height, aRow.HeightRule
      Next aRow
    Else
      Debug.Print "Table has merged cells"
      For Each aCell In aTable.Range.Cells
        If aCell.ColumnIndex = 1 Then Debug.Print aCell.Height, aCell.HeightRule
      Next aCell
    End If
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-14-2021, 03:05 PM
eduzs eduzs is offline Retrieve row height merged cells Windows 10 Retrieve row height merged cells Office 2019
Expert
Retrieve row height merged cells
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

Thanks Guessed!
I tested here and worked perfectly.
Sorry! I asked to delete the topic, because I ended up doing it manually cause was not a very large table, but the code is saved for the next use.
I restored the original post.
__________________
Backup your original file before doing any modification.
Reply With Quote
  #4  
Old 03-14-2021, 04:29 PM
eduzs eduzs is offline Retrieve row height merged cells Windows 10 Retrieve row height merged cells Office 2019
Expert
Retrieve row height merged cells
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

I noticed that this code also works for error 5992 when accessing the column width when the table has mixed column width.
Now to modify the width of a table (with vertically merged cells and cells with mixed width), I don't need to unmerge cells (and many ther steps) anymore, something simple like aCell.Width = 1.1 * aCell.Width do the trick.
Thank you very much.
__________________
Backup your original file before doing any modification.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve row height merged cells Table Row with merged cells andi_bln Word VBA 3 10-15-2020 01:22 AM
Retrieve row height merged cells Converting table to text (and back) with carriage returns in cells, split and merged cells ndajko Word 5 11-04-2019 07:53 AM
Borders on merged cells also appearing on unwanted adjacent cells MrsC Word Tables 2 08-19-2019 09:14 AM
Retrieve row height merged cells Problem with merged cells and row height in adjacent two- and three-row columns rolandoftheeld Word Tables 3 08-31-2018 03:55 PM
Retrieve row height merged cells Table will not allow sorting because "cells are merged". I can't find the merged cells. wendyloooo Word Tables 1 05-26-2015 01:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft