Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if existis value stop macro.... (2000 sr 1)

    Sub IMPORT_L0785()

    Set ELENCO = Worksheets("L0785_TOTALE")
    cont = FirstFree("L0785_TOTALE", "A", 6) 'Record iniziale per il riempimento del tabulato

    iFile = FreeFile()
    vFile = ("C:EPFL0785.EPF")

    Open vFile For Input As #1

    While Not EOF(1)

    Line Input #1, RIGA
    If Len(Trim(RIGA)) > 0 Then
    If InStr(Mid(RIGA, 1, 12), "DATA CONTAB.") > 0 Then
    var_DATACONT = Mid(RIGA, 15, 10)
    End If
    If InStr(Mid(RIGA, 1, 11), "DIPENDENZA:") > 0 Then
    var_DIP = Format(Mid(RIGA, 14, 4), "#00000")
    End If
    ........... ecc..

    ELENCO.Range("A" & Trim(Str(cont))).Value = var_DATACONT
    ELENCO.Range("B" & Trim(Str(cont))).Value = var_DIP
    ELENCO.Range("C" & Trim(Str(cont))).Value = var_COD

    ecc...

    this is a piece of macro to import txt file.
    I would want to controll if he same file is imported twice...

    my idea:

    Into sheet CONTROLLO (this sheet naturally is present into same wbook where i make the txt import file)insert for every import file the value of vriable var_DIP (and add up the next variable refred from other next txt file imported).
    From a next import file if the value of var_DIP is olready present into sheet CONTROLLO make to appear a msbox" this file is alreday imported, retry another" exit sub and stop macro....
    I hope to be clear my idea.....;-)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: if existis value stop macro.... (2000 sr 1)

    Change While ... to Do While... and Wend to Loop

    Below the line var_DIP = Format(Mid(RIGA, 14, 4), "#00000"), insert this piece of code:

    Dim rngDip As Range
    Set rngDip = Worksheets("Controllo").Range("A:A").Find(What:=va r_DIP, LookIn:=xlValues, LookAt:=xlWhole)
    If rngDip Is Nothing Then
    Worksheets("Controllo").Range("A65536").End(xlUp). Offset(1, 0) = var_DIP
    Else
    MsgBox "This file has already been imported!"
    Exit Do
    End If

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if existis value stop macro.... (2000 sr 1)

    Good... and tks.
    But why EXIT DO and not EXIT SUB, only to understand....

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: if existis value stop macro.... (2000 sr 1)

    Exit Do only makes you leave the Do While ... Loop part, not the entire IMPORT_L0785 procedure. This is important, for you still have to close the text file.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if existis value stop macro.... (2000 sr 1)

    .... aaaaaaaahhh

Posting Permissions

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