+ Reply to Thread
Results 1 to 2 of 2

Macro for data validation

Hybrid View

  1. #1
    Registered User
    Join Date
    08-06-2014
    Location
    Poland
    MS-Off Ver
    MS Office 2010
    Posts
    1

    Macro for data validation

    Hi guys!

    I'm looking for a macro which is going to validate the data based on variables given. I have on sheet with two columns, each containing different data: id number and discount rate. In an external file is the place where data from previous file are copied. The procedure is as following: You open file1, copy the data from column 1&2, paste it into column 1&2 in file2 and get the result in column 3 based on the pasted values(ok/not ok - simple IF formula). I need macro that is going to choose and open the file2, copy the values form file1 to file2 and then mark the entries in column 2 of file1 if they are ok/not ok

    Thanks for help!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,283

    Re: Macro for data validation

    Why not put the sheets together into one workbook - anyway, try this code in file2, and run it, choosing file1 when the dialog appears: This will fill the cells of column 2 with color based on OK Not OK...

    Sub Test()
        Dim W As Workbook
        Dim i As Long
        Set W = Workbooks.Open(Application.GetOpenFilename)
        With W.Sheets(1)
            .Range("A:B").Copy ThisWorkbook.Sheets(1).Range("A:B")
            Application.CalculateFull
            For i = 1 To .Cells(.Rows.Count, "B").End(xlUp).Row
                If UCase(ThisWorkbook.Sheets(1).Cells(i, "C").Value) = "OK" Then .Cells(i, "B").Interior.ColorIndex = 4
                If UCase(ThisWorkbook.Sheets(1).Cells(i, "C").Value) = "NOT OK" Then .Cells(i, "B").Interior.ColorIndex = 3
            Next i
        End With
        'Uncomment the next line to save and close the workbook
        'W.Close True
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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. Macro that detects and circles invalid data automatically (Data Validation)
    By dchubbock in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2012, 09:07 AM
  2. I need a macro to enter data based on data validation lists.
    By DorothyFan1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-30-2012, 08:58 AM
  3. Stop Worksheet_Change macro if validation not met in Data Validation
    By Wizz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2010, 12:26 PM
  4. Data validation macro
    By matpj in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-18-2006, 10:36 AM
  5. run a macro with data validation?
    By e02hm in forum Excel General
    Replies: 2
    Last Post: 04-25-2005, 10:10 AM

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