+ Reply to Thread
Results 1 to 3 of 3

Integrating leave blank cell if error into existing code

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2014
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Integrating leave blank cell if error into existing code

    Hey all,

    I need help to integrate 'make cell blank if there is an error' into my existing code.

    Currently, when I get an error, the macro will use the cell value of the most recent non-error cell. What happens is that I will get duplicate entries for all my error cells, until a non-error text is read.

    Anyone knows how to integrate the leave blank cell if error into my existing code?

    Code:

    Sub all3()
    Dim myfile
    Dim FSO As FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim Res As String, temp As String
    myfile = Application.GetOpenFilename("Txt files (*.txt), *.txt", , "Please select your file or files", , True)
    Dim x As Long
    Dim y As Long
    y = 1
    If IsArray(myfile) Then
        For x = LBound(myfile) To UBound(myfile)
            temp = FSO.GetFile(myfile(x)).OpenAsTextStream.ReadAll
        On Error Resume Next
            Res = Left(Mid(temp, InStr(1, temp, "2. ", vbTextCompare)), InStr(Mid(temp, InStr(1, temp, "2. ", vbTextCompare)), vbLf))
            Range("E" & y).Value = Res
            y = y + 1
        Next
    
    End If
    Set FSO = Nothing
            
    End Sub
    Last edited by WinningKing; 03-05-2014 at 09:35 PM.

  2. #2
    Registered User
    Join Date
    02-19-2014
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Integrating leave blank cell if error into existing code

    Is there a way to edit the 'On Error Resume Next' such that when an error is received, make the error cell give a value of 0 before resuming?

  3. #3
    Registered User
    Join Date
    08-06-2013
    Location
    Quebec
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Integrating leave blank cell if error into existing code

    What about adding something like that?

    If Err.Number <> 0 then
    'Your commands here Err.Clear
    End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 09-20-2013, 01:43 PM
  2. Leave blank if error
    By leem in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2010, 09:21 AM
  3. Leave cell blank when there is an error
    By Cerberus in forum Excel General
    Replies: 2
    Last Post: 06-30-2010, 01:30 PM
  4. [SOLVED] Leave Cell Blank if value is an error, below 0 or above 80
    By SteveC in forum Excel General
    Replies: 4
    Last Post: 05-12-2006, 09:34 AM
  5. Leave existing data in a cell alone
    By Running Out of Ideas in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-29-2006, 09:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1