Display UsedRange of Excel spreadsheet VBScript
How would I display the used range of an excel spreadsheet?
I tried:
Code:
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?
Re: Display UsedRange of Excel spreadsheet VBScript
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?
Re: Display UsedRange of Excel spreadsheet VBScript
Sorry, I meant how to show what the used range is. Like if there is data in the spreadsheet from A1 to C12, then
Code:
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
Code:
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?
Re: Display UsedRange of Excel spreadsheet VBScript
Code:
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
Re: Display UsedRange of Excel spreadsheet VBScript