Results 1 to 4 of 4

Code in excel file to automatically run when manually copy pasting downloaded excel data

Threaded View

ExcelerNew Code in excel file to... 06-14-2017, 05:17 AM
bakerman2 Re: Code in excel file to... 06-14-2017, 07:24 AM
ExcelerNew Re: Code in excel file to... 06-14-2017, 07:35 AM
bakerman2 Re: Code in excel file to... 06-16-2017, 01:06 AM
  1. #1
    Registered User
    Join Date
    06-14-2017
    Location
    uk
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Unhappy Code in excel file to automatically run when manually copy pasting downloaded excel data

    Hi All,
    I am quite new to vba and have been trying to put together codes available online but unfortunately is not working due to my lack of background knowledge.

    What I would like to do is whenever I download excel dataset with updated data (i.e. each month's data added) from the website & manually copy paste into my excel file (which I will be using for reporting purposes) into the worksheet named "All_Data", the code to check for 3 conditions (specialLookUp) should run automatically and the resulting subset must appear in Sheet2.

    Initially I used just the Subroutine specialLookUp and it worked but when I copy pasted the downloaded data into "All_Data" Worksheet it stopped working, then I tried to add the Worksheet_change and other bits.

    All of this code is in Module1.

    Please help!

    Here's the code:


    Public PreVal As Variant
    
    Private Sub Workbook_Open()
        PreVal = All_Data.Range("B1:P500").Value2
    End Sub
    
    Public Sub Worksheet_Change(ByVal Target As Range)
    Dim woArea As Range, isect As Range
    Set woArea = All_Data.Range("B1:P500")
    Set isect = Application.Intersect(Target, woArea)
    
    If isect Is Nothing Then
        specialLookUp
    Else
        Worksheet_Calculate
    End If
    End Sub
    
    Private Sub Worksheet_Calculate()
    If All_Data.Range("B1:P500").Value2 <> PreVal Then
    specialLookUp
    PreVal = All_Data.Range("B1:P500").Value2
    End If
    End Sub
    
    Public Sub specialLookUp()
        Dim keyword As String: keyword = "Client Email"
        Dim keyword2 As String: keyword2 = "Client Email Reply"
        Dim keyword3 As String: keyword3 = ""
        
        Dim countRows1 As Long, countRows2 As Long
        countRows1 = 2 'the first row of dataset in sheet1
        endRows1 = 500 'the last row of dataset in sheet1, make sure to increase this value based on dataset increase after download
        countRows2 = 2 'the first row where you want to start writing the found rows
        For j = countRows1 To endRows1
            If (Sheets("All_Data").Range("B" & j).Value = keyword Or Sheets("All_Data").Range("B" & j).Value = keyword2) And Sheets("All_Data").Range("I" & j).Value = keyword3 Then
                            Sheets("sheet2").Rows(countRows2).Value = Sheets("All_Data").Rows(j).Value
            countRows2 = countRows2 + 1
        End If
        Next j
    End Sub
    Last edited by ExcelerNew; 06-14-2017 at 08:16 AM. Reason: As per Forum rule 3

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel macro fail launch automatically in Task Scheduler , but run file manually
    By waihar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-15-2016, 07:57 PM
  2. Replies: 1
    Last Post: 03-31-2015, 03:01 PM
  3. Automatically Copy contents from One column of One excel file to Another excel file
    By sarabjit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2014, 08:11 PM
  4. [SOLVED] Automatically Copy Data in Excel File upon opening email attachment
    By rachaelgoldman1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2013, 05:21 AM
  5. [SOLVED] (URGENT) Search for matching data, copy and pasting from a closed excel file
    By dani_n88 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-07-2012, 02:31 PM
  6. Automatically Copy Data into Worksheet from Different Excel File
    By mwgr5 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 07-21-2010, 01:48 PM
  7. Copy data from excel file to Web Form automatically
    By vandanavai in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-15-2008, 10:54 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