+ Reply to Thread
Results 1 to 8 of 8

Copy cell into another if it contains 7 characters

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2016
    Location
    Bluffton, Ohio
    MS-Off Ver
    2013
    Posts
    6

    Copy cell into another if it contains 7 characters

    I need help writing a macro to do the following.

    If cell A1 contains 7 characters then copy it to cell Z1, if not put in dummy 7 characters XXXXXXX
    Keep evaluating each row if it doesnt contain 7 characters in column A paste the last cell in column A that did in column Z, if it does contain 7 characters then paste that in column Z and continue to use that value until in column Z until another 7 characters is found in column A.

    EX.
    A1 = AAA Then Z1 = XXXXXXX
    A2 = BBBBBBBBB Then Z2 = XXXXXXX
    A3 = ABCDEFG Then Z3 = ABCDEFG
    A4 = CCC Then Z4 = ABCDEFG
    A5 = 9/23/2015 Then Z5 = ABCDEFG
    A6 = BCDEFGH Then Z6 = BCDEFGH
    A7 = DDD Then Z7 = BCDEFGH
    A8 = 10/23/15 Then Z8 = BCDEFGH
    A9 = AAAAAAAAA Then Z9 = BCDEFGH
    A10 = CDEFGHI Then Z10 = CDEFGHI
    . . . . . and so on.

    Any help would be appreciated. Thanks!
    Last edited by jriemanx2; 04-07-2016 at 05:39 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro Help Needed

    What's the relevance of mentioning a date? From your example it seems this is irrelevant.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Macro Help Needed

    or if your example is actually an example then a sheet is much better than just typing it into the post.

  4. #4
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Macro Help Needed

    Also please

    1) change your title to one that that describes your problem
    2) put code inside code tags

    as per forum rules.

  5. #5
    Registered User
    Join Date
    04-04-2016
    Location
    Bluffton, Ohio
    MS-Off Ver
    2013
    Posts
    6

    Re: Copy cell into another if it contains 7 characters

    You are correct, being a date should not matter. I have updated the verbage and the title.
    Thanks!

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,663

    Re: Copy cell into another if it contains 7 characters

    withdrawn...
    Last edited by protonLeah; 04-08-2016 at 04:52 PM.
    Ben Van Johnson

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,666

    Re: Copy cell into another if it contains 7 characters

    VBA?
    Sub test()
        With Range("a1", Range("a" & Rows.Count).End(xlUp)).Columns("z")
            .Formula = "=if(len(a1)<>7,if(row()=1,rept(""X"",7),offset(Z1,-1,0)),A1)"
            .Value = .Value
        End With
    End Sub

  8. #8
    Registered User
    Join Date
    04-04-2016
    Location
    Bluffton, Ohio
    MS-Off Ver
    2013
    Posts
    6

    Re: Copy cell into another if it contains 7 characters

    The VBA code worked perfectly.
    Thanks!!

+ 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. Replies: 0
    Last Post: 01-03-2014, 10:04 AM
  2. EXCEL MACRO is attached. THIS MACRO is needed in ACCESS
    By cooldebi in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2011, 04:01 PM
  3. [SOLVED] Macro help needed
    By anon125 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2009, 07:56 PM
  4. Macro help needed
    By Aussie_Striker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2007, 05:32 AM
  5. Macro needed to set macro security in Excel to minimum
    By Carl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2006, 11:40 AM
  6. Macro needed
    By Randall Roberts in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. Macro needed to Paste Values and prevent Macro operation
    By thunderfoot in forum Excel General
    Replies: 1
    Last Post: 06-10-2005, 08:05 PM
  8. Macro needed to Paste Values and prevent Macro operation
    By thunderfoot in forum Excel General
    Replies: 0
    Last Post: 06-10-2005, 03:05 PM

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