+ Reply to Thread
Results 1 to 10 of 10

How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each column)

  1. #1
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each column)

    Hello,
    I am new to VBA. I have the data in a sheet 1 with 100+ columns. In sheet 2 i have validation formula(Regular Expressions) for each column. i wants to copy data from sheet 1 to sheet 3 by checking validation formula of each column before pasteing the data in sheet 3. If it satisfies Regex, copy that in sheet 3 and fill the cell with green color or if not satisfies copy data to sheet 3 and fill that cell with red color. Below is images of sheet1,2,3.

    Capture4.JPG
    Capture3.JPG
    Capture2.JPG

    I am not getting idea how to achieve this in VBA.

    Thanks in advance

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Maybe :

    Please Login or Register  to view this content.
    Attached Files Attached Files
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Thank you for answer
    Code is working well but if i change data in Account Number to "asd"(Wrong data) then after checking regular expression it showing OK. i wants to change in code like check first cell in Account Number column if it true (Satisfies Regex) then fill cell with Green color else make it red and similar to all data.
    Simply i wants to check columnwise, first check Account Number Column cell by cell if true make green and false then make Red.
    If one of the cell in whole row contains wrong data then in "OK/NG" Column write NG and if whole row is correct then write it as Ok. plz see the attachment.

    Capture5.JPG

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Code is working well but if i change data in Account Number to "asd"(Wrong data) then after checking regular expression it showing OK.
    Do you understand regular expression syntax ?
    From your screenshot, on Sheet2!B2, the regular expression for "Account Number" is "^[a-zA-Z0-9]+$"
    This means: lowercase a to z, uppercase A to Z, number 0 to 9 should be allowed, but you said "asd" is wrong data ?
    If you want this column is number only, then the regular expression should be "^[0-9]+$" (just the same as for the Bank Code on cell Sheet2!B9)

    Also for "Address", "Bank Name", "Bank Branch", "Bank Address", your regular expression is "^[A-Z0-9\s/\-\?:\(\)\.,'\+]+$"
    Notice that there is no a-z, which means lowercase is forbidden, but from your screenshot on post #3, for cell B2 for example, you mark this cell as green while it should be red (lowercase is forbidden).

    -----------------------------------

    This is the modified code as your request to test and mark individual cell (not whole row) :

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Thank you for answer......sorry i made mistake in asking question but u gave write answer .....Thank you so much

    But if i wants to create new workbook in a folder and copy sheet3 to new sheet in new workbook (wit populated color same as sheet 3) without column OK/NG. Where i should make changes . can i add that code to this code or i should write new code for creating new workbook and copy sheet 3 data to new workbook.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    You are welcome.

    It's up to you which method you will choose. Here I provide the second method, this Sub Test2() will call Sub Test() and then copy the output to a new workbook.
    If you want the first method, then just add the code of this SubTest2() to the end of Sub Test() (remove the "Call Test" line).

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Thank you very much for your Answer........!!!!!!!!!!!
    Code is Running Properly.........!!!!!!!!!!!

    i wants to make header name in "Report.xls" in Blue Color and all columns should be autofilterd.
    and i wants to store ouput file path is given in sheet4. Where should i make changes.
    Cap.JPG
    Last edited by Amar321; 06-23-2016 at 06:48 AM.

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Thank you code is working very well....!!!!!!!!!!

    But the problem is i have executed it first time the report is file is generated successfully. Without deleting the report.xls file from output path , i tried to execute code second time, the second report.xls file is not get generated but previous file gets overwrited. when i go to execute it for second time it should not overwrite previous file new file should be created.
    Last edited by Amar321; 06-27-2016 at 01:01 AM.

  10. #10
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    Re: How to Copy data from Sheet 1 to sheet 3 by using sheet 2 (Contains Regex of each colu

    Hello,
    The problem i am facing is, i have executed it first time the report is file is generated successfully. Without deleting the report.xls file from output path , i tried to execute code second time, the second report.xls file is not get generated but previous file gets overwrited. when i go to execute it for second time it should not overwrite previous file new file should be created.

+ 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. [SOLVED] Macro who copy the data from one sheet to another sheet basis of 2 other column cell value
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2015, 12:47 PM
  2. [SOLVED] Macro who copy the data from one sheet to another sheet basis of 2 other column cell value
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2015, 09:49 AM
  3. [SOLVED] Macro to Copy data from one sheet to another sheet if column headings match
    By harman83 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-04-2015, 02:40 AM
  4. [SOLVED] Copy Column A data to Sheet 2 where rows matches Sheet 2 headers
    By SCDE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2015, 12:14 AM
  5. Replies: 2
    Last Post: 01-22-2014, 05:36 PM
  6. Copy column data on one sheet to row or column date on another sheet based on user in
    By soready42012 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2012, 12:03 AM
  7. Replies: 1
    Last Post: 10-30-2009, 10:58 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