Click to See Complete Forum and Search --> : Display UsedRange of Excel spreadsheet VBScript
dizou
August 22nd, 2008, 01:14 PM
How would I display the used range of an excel spreadsheet?
I tried:
MsgBox objExcel.Worksheets(1).UsedRange
This did not work, so how would I do something like this? Is there also some way to get the total number of used columns and total number of used rows? If you could tell me how to do this in Visual Basic Script that would be great. Visual Basic 6 or VB.Net code is ok. I'm assuming they are going to be similar?
javajawa
August 22nd, 2008, 03:01 PM
What do you mean by "display", and what do you mean by "did not work".
As far as I can tell, the UsedRange property works perfectly - it represents the smallest possible rectangle which contains all the calls without null values.
What exactly do you want to get?
dizou
August 22nd, 2008, 03:10 PM
Sorry, I meant how to show what the used range is. Like if there is data in the spreadsheet from A1 to C12, then objExcel.Worksheets(1).UsedRange would be A1:C12. I would like to display this in a MsgBox. The code I had above didn't work because objExcel.Worksheets(1).UsedRange isn't in a format that MsgBox can display. So how do I get that into a format I can display with a MsgBox. Also, how do I get the total number of rows and columns used in a spreadsheet?
javajawa
August 22nd, 2008, 03:19 PM
Starting Column: UsedRange.Column
Number of Columns: UsedRange.Columns.Count
Starting Row: UsedRange.Row
Number of Rows: UsedRange.Rows.Count
Public Function ExcelColHead(ByVal ColNum As Integer) As String
Dim T As Byte
If ColNum > 26 Then
T = (ColNum Mod 26)
ColNum = (ColNum - T) / 26
ExcelColHead = Chr(64 + ColNum) & Chr(64 + T)
Else
ExcelColHead = Chr(64 + ColNum)
End If
End Function
dizou
August 22nd, 2008, 04:04 PM
That's great thanks!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.