Results 1 to 2 of 2

Trying to avoid updating a source document when executing a FOR loop

Threaded View

VictorAmor Trying to avoid updating a... 06-14-2017, 04:04 AM
xlnitwit Re: Trying to avoid updating... 06-14-2017, 04:15 AM
  1. #1
    Registered User
    Join Date
    05-30-2017
    Location
    Madrid
    MS-Off Ver
    Excel 2016
    Posts
    1

    Trying to avoid updating a source document when executing a FOR loop

    Hi guys,

    I have been developing a Macro that does multiple VLOOKUPs depending en how many variables I want to search from other document. The source document may be variable, so I define it as a Variant (you will see it in the code)

    Everything seems working fine although a little issue that actually pisses me off. When the for loop executes, excel constantly asks me to update the SourceFile document by opening a browser and it makes the macro useless. I don't know any solution for this incidence. Would anyone help me?

    Thanks
    Sub VLOOKUPs()
    
    'Declare the variables
      Dim FilterIndex As Long
      Dim Title As String
      Dim SourceFile As Variant
      Dim n, counter, column As Integer
      Dim LR As Long
    
    ' Display *.* by default
      FilterIndex = 5
    ' Set the dialog box caption
      Title = "Select a File to Import"
    ' Get the filename
     SourceFile = Application.GetOpenFilename(, FilterIndex, Title)
    ' Handle return info from dialog box
      If SourceFile = False Then
        MsgBox "No file was selected."
      Else
        MsgBox "You selected " & SourceFile
      End If
    
    'VLOOKUP
    Range("A9").Activate
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC2,'[(SourceFile)]Category data'!R1:R12000,R8C,FALSE)"
    
    ' Autofills the column depending on how many articles exists on the template
    LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("A9").AutoFill Destination:=Range("A9:A" & LR)
    
    ' Completes all the following columns
    Range("A7").Select
    n = Range(Selection, Selection.End(xlToRight)).Count
    For counter = 7 To n
    column = counter
    Cells(9, column).Activate
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC2,'[(SourceFile)]Category data'!R1:R14000,R8C,FALSE)"
    Next
    
    End Sub
    Last edited by VictorAmor; 06-14-2017 at 04:26 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Stop timer, Do While Loop from executing.
    By Wijnand1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-28-2017, 03:24 AM
  2. Updating source document after Vlookup table changes
    By trstew in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-28-2016, 11:50 PM
  3. [SOLVED] How to avoid displaying movement across sheets while executing the vba code
    By saviour2009 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 05:26 AM
  4. [SOLVED] Nested IF only executing first loop statement
    By kewcumber in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-22-2012, 03:51 PM
  5. Stop Document auto updating from a remote source
    By willneal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2010, 10:19 AM
  6. How can I avoid changing a loop counter within a loop?
    By broro183 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2009, 07:59 PM
  7. Executing a subroutine from within a loop
    By Jeff@DE in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2006, 06:10 AM

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