LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Co Co is offline
external usenet poster
 
Posts: 4
Default problem with UsedRange

Hi All,

I use a code in VBA that will extract text from an excel worksheet.
I use the UsedRange option to get the row and colums with text.
Recently I had a worksheet that had 14434 rows of which maybe 20 were
with text.
The code kept cycling until it reached row 14434.
Is there a way to get only the lines with text?

Public Function Excel2Text(sInputFile As String, sOutputFile As
String, Sep As String)

'Sep:=";"
Dim oAppl As Excel.Application
Dim oWorkbook As Excel.Workbook
Dim oSh As Object
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Dim sTempName As String

On Error GoTo EndFunction:
Set oAppl = New Excel.Application
Set oWorkbook = oAppl.Workbooks.Open(Tempdir & sInputFile, False,
True)

oAppl.Visible = False
oAppl.ScreenUpdating = False
FNum = FreeFile

sTempName = Mid$(sOutputFile, 1, InstrRev(sOutputFile, ".", -1)) &
"TXT"
Open geheugen.gTempDirZoekWoorden & sTempName For Output Access Write
As #FNum

For Each oSh In oWorkbook.Sheets

With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
Next

EndFunction:
On Error GoTo 0

Close #FNum

oAppl.Quit
Set oWorkbook = Nothing

End Function


Regards
Marco
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UsedRange?? problem Geoff Excel Programming 4 April 10th 08 03:48 PM
usedRange problem Hemant_india[_2_] Excel Programming 7 July 14th 06 10:02 AM
Excel VBA - UsedRange problem cata_and Excel Programming 6 June 4th 04 11:56 AM
UsedRange problem Kobayashi[_26_] Excel Programming 4 January 30th 04 05:17 PM
UsedRange problem Andy Excel Programming 2 September 18th 03 05:17 PM


All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"