Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2011, 09:55 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default Macro or user function to Extract row height


Hi there,
I have a problem that i need to solve fast, time is very short...
The problem is:
i have an input worksheet, with several rows formated as text, with row height set to autofit.
This text rows, i need to import in a collector worksheet, which gets data from lots of worksheets. The problem is that in the collector worksheet, i cannot set row height to autofit, and i have to find a way to extract the row height from the text input worksheet and use this height to format the collector worksheet rows...
The challenge is that i change frequently the text source( the collector is always the same) and i cannot edit links in VBA.
I am sure there is a simple solution to this, like a user defined function, and i need a start point...
Thanks in advance
Reply With Quote
  #2  
Old 06-21-2011, 12:07 PM
gjcase gjcase is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Novice
 
Join Date: Jun 2011
Posts: 7
gjcase is on a distinguished road
Default

Here's an example:

Sub RowHt()
Dim HT As Single
HT = Rows("12:12").RowHeight

MsgBox ("Row height is " & HT)

End Sub
Reply With Quote
  #3  
Old 06-21-2011, 10:34 PM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

thank you gjcase,
that code informs me about the row height, and i dont have the posibility to change the source worksheet . I need to use this information to set the row height in another worksheet
I tried instead this code, which works fine, but only when the source worksheet is OPEN, otherwise returns the #VALUE! error. How can i get rid of this error?
here is the code:

Option Explicit

Public Function RowHeight(ByVal rngHeight As Range) As Single

Dim rngRow As Range

For Each rngRow In rngHeight.Rows
RowHeight = RowHeight + rngRow.RowHeight
Next

End Function

=RowHeight('\\Flory\D\Sesiunea 4 - 141-iunie 2011\Dodan Danut\[text plan afaceri 141 - Dodan Danut.xls]text plan'!$A7))
Reply With Quote
  #4  
Old 06-22-2011, 02:10 AM
OTPM OTPM is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
May I suggest you use your current Macro to open the other worksheet and make the changes and then save and close it as part of your macro.

Hope this helps.

Tony(OTPM)
Reply With Quote
  #5  
Old 06-22-2011, 02:55 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Thanks, Tony
The problem is that the source workbook name is always different, and this cannot be easily done in VBA (to change the links to another workbook).
Reply With Quote
  #6  
Old 06-22-2011, 04:13 AM
OTPM OTPM is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
In that case you can use an INPUT syntax within the VBA code to ask for the workbook name each time you run the code.
Hope this helps.
Tony(OTPM)
Reply With Quote
  #7  
Old 06-22-2011, 06:56 AM
gjcase gjcase is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Novice
 
Join Date: Jun 2011
Posts: 7
gjcase is on a distinguished road
Default

Catalin:

I'm confused. I assume you are reading data from other workbooks (vs worksheets, which would be contained within the same workbook, and therefore always accessible.) However, to read the data, you must have the source workbook open, and therefore you should be able to read the row height at the same time, correct?

I agree with Tony, a macro which opens each source, reads the data and rowheight, and writes that to the collector and then closes the source, would seem to be the way to go.
Reply With Quote
  #8  
Old 06-22-2011, 07:13 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

You are right, gjcase,
text data are in separate workbook.
But to read the data from that workbook, it is not necesary for that workbook to be opened.
Only the macro with User Defined Function looks like it is not working with the source workbook closed.
Excuse me for the confusion i created...
Looks like there is no other option but to open it so i can read the row height...
Thanks for advices, gjcase and Tony
Reply With Quote
  #9  
Old 06-22-2011, 07:50 AM
gjcase gjcase is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Novice
 
Join Date: Jun 2011
Posts: 7
gjcase is on a distinguished road
Default

Another solution might be to read the data into a workbook for which you can apply an autofit, and then read from this intermediate file the row height info into your collector workbook.
Reply With Quote
  #10  
Old 06-22-2011, 08:07 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Dear friend, i do have a link between workbooks, but if i apply autofit to the cell containing the link to the source workbook, the height of the row will always be 15, no matter how long is the text.
I am working to a solution which counts characters in text : =LEN(A1), and to set the row height depending on this count. At first evaluation, looks like this method does not need the source workbook to be open...
Thanks again for your time gjcase, i will let you know if i find an acceptable solution, and please let me know if you have a better way
Reply With Quote
  #11  
Old 06-22-2011, 08:40 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Let there be problems, so we can find solutions...
in column B , i entered this formula: =LEN('C:\Users\Catalin\Desktop\Iordachi Gh. Gheorghe\[text plan afaceri 141 -Iordachi Gh. Gheorghe .xls]text plan'!$A7). The result is a number which i can use to set the row for 130 characters in a row, with a formula , in column C: =CEILING(15*D5/130;15) The result is a multiple of 15, 30, 45, 60, depending on text length.
And finally, the macro works great...

Sub Height()
Application.ScreenUpdating = False
Rows("565:565").RowHeight = Sheets("Rand").Range("C22")
Rows("566:566").RowHeight = Sheets("Rand").Range("C23")
Rows("595:595").RowHeight = Sheets("Rand").Range("C25")
Rows("597:597").RowHeight = Sheets("Rand").Range("C26")
Rows("599:599").RowHeight = Sheets("Rand").Range("C27")
Rows("600:600").RowHeight = Sheets("Rand").Range("C28")
Rows("4:4").RowHeight = Sheets("Rand").Range("H5")
Rows("65:65").RowHeight = Sheets("Rand").Range("H6")
Rows("214:214").RowHeight = Sheets("Rand").Range("H7")
Rows("215:215").RowHeight = Sheets("Rand").Range("H8")

Application.ScreenUpdating = True
End Sub
Many thanks to gjcase and Tony, for guidance through this process, you're great guys!
Reply With Quote
  #12  
Old 06-22-2011, 09:04 AM
gjcase gjcase is offline Macro or user function to Extract row height Windows 7 32bit Macro or user function to Extract row height Office 2010 32bit
Novice
 
Join Date: Jun 2011
Posts: 7
gjcase is on a distinguished road
Default

Catalin:

See the attached files. I have a source file, Book3.xlsm, an intermediate file, Intermediate.xlsm, which reads the data from the source, runs an autofit, and copies to the third file, collector.xlsm. See if this does what you are after.
Attached Files
File Type: xlsm Book3.xlsm (9.0 KB, 12 views)
File Type: xlsm Intermediate.xlsm (20.7 KB, 12 views)
File Type: xlsm collector.xlsm (8.3 KB, 13 views)
Reply With Quote
  #13  
Old 06-22-2011, 09:21 AM
Catalin.B Catalin.B is offline Macro or user function to Extract row height Windows Vista Macro or user function to Extract row height Office 2007
Expert
Macro or user function to Extract row height
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Yes, gjcase, this is exactly what i need, only the intermediate is unnecessary, i will adjust the macro to copy directly from book 3 in collector.
Great solution, gjcase, thanks a lot.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting HTML into Excel (height auto-adjust) c-tran Excel 0 03-11-2010 07:30 AM
automatic start of macro + help on writing helper function vsempoux Word 3 10-09-2009 03:01 AM
Macro or user function to Extract row height Macro or Function to know wether a string is included in a text Eduardo Word VBA 5 06-15-2009 01:55 AM
Macro or user function to Extract row height Help! for using an appropriate function/Macro in Excel pawan2paw Excel 1 06-04-2009 12:28 PM
Validate the height of the text when you save (VBA) jhpe Word VBA 0 08-22-2008 06:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:56 AM.


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