+ Reply to Thread
Results 1 to 2 of 2

IF Statement Across Workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2016
    Location
    Copenhagen
    MS-Off Ver
    2016
    Posts
    3

    Lightbulb IF Statement Across Workbooks

    Hi Guys,

    I have two workbooks, one contains ALL the data, the other contains the newest and relevant data. One is the COPY book the other is PASTE book.

    I would like to write a code that says: If column B contains "Active" then copy columns A, C, and D to the other workbook.

    Problems:
    1: sometimes the B column returns #VALUE because it is based on a formula that tests the dates. That is why I am trying to use IFERROR
    2: I don't want ALL the content of the COPY sheet. I would like the following columns: A & C:P.

    Sub CopyPaste
    
    Dim CopyFrom As Excel.Workbook
        Set CopyFrom = Excel.Workbooks("CopyBook.xlsx")
        
    Dim CopySheet As Excel.Worksheet
        Set CopySheet = CopyBook.Worksheets("CopySheet")
        
    Dim WorkRange
        WorkRange = CopySheet.Cells(1).CurrentRegion.Value 
    'I have had succes with this code before, it should save the current selection of the IF STATEMENT as a value so that I can write (Copy WorkRange(i, A+C+D) to Destination.)
        
    Dim i As Long
    
        For i = 3 To UBound(WorkRa, 1)
    If Not WorkRange(i, 2) Is Nothing Then 'This line says that if the second column (here B) is not nothing / not black, then continue
    If Not IsError(wkrngA(i, 2)) Then ' This line says that if the second column (here B) is not an error, then continue
    If WorkRange(i, 2) = "Active" Then
    'Print values from WorkRange(i, columns A, B and C) to PasteSheet.Cells(1,1)
    End If
    End If
    End If
    Next i End Sub
    I have tried for many hours, but these are all pretty new functions to me. Can somebody please help? Also, when answering, please explain the code so that I can learn more.


    Sincerely,

    Jacob

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: IF Statement Across Workbooks


    Hi !

    As using a loop can be often the slowest way, as using an Excel basics like a filter or an advanced filter no needs any loop …

+ 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. IF Statement across 2 workbooks
    By Andy42k in forum Excel General
    Replies: 6
    Last Post: 07-28-2018, 01:38 AM
  2. Linking cells between workbooks if IF statement is satisfied
    By Mattgee in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-09-2015, 02:02 AM
  3. Error on basic Workbooks.open statement
    By blueben in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-08-2015, 08:47 AM
  4. Replies: 1
    Last Post: 07-19-2012, 06:23 AM
  5. Conditional Statement either in excel or vb for two separate workbooks
    By cairne in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-20-2009, 03:08 PM
  6. IF STATEMENT in multiple workbooks.
    By Yunus Patel in forum Excel Formulas & Functions
    Replies: 46
    Last Post: 09-06-2005, 09:05 PM
  7. Copy between workbooks if statement is true
    By Ingeborg AV in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2005, 04:05 PM

Tags for this Thread

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