+ Reply to Thread
Results 1 to 17 of 17

Copy 10 digits in a numbers and paste to another column

Hybrid View

  1. #1
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Copy 10 digits in a numbers and paste to another column

    Hello,

    please help me to edit my code i need to copy 10 digits of number in column W

    raw data
    
    column W                       column X
                                         56883088845688308885
                                         5606667478
                                         568831077656883104645688311506
    
    Finish
    
    column W
    5688308884
    5688308885
    5606667478
    5688310776
    5688310464
    5688311506
    I've also attached my file.

    THanks
    Attached Files Attached Files
    Last edited by 6StringJazzer; 10-28-2016 at 02:09 PM. Reason: code tags to preserve spacing of data

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

    Re: Copy 10 digits in a numbers and paste to another column

    withdrawn.........
    Last edited by protonLeah; 10-28-2016 at 08:38 PM.
    Ben Van Johnson

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Copy 10 digits in a numbers and paste to another column

    Hello ash3angel,

    According to your required sample data, how is the system to know when you want ten numbers from the left, or from the right, or even maybe somewhere in between?

    For Example: 5688308884 are numbers from the left of 56883088845688308885

    and then : 5688308885 are numbers to the right of 56883088845688308885

    This will not be possible.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    I have attached the macro file, the only thing i am missing is when i copy the first 10 digit and paste it in column W then it will copy again the 2nd 10 digits and when copying the 2nd row data it won't copy it anymore because it will not do the loop because its blank or when trying to change it i will skip or will just continue to loop

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    Does this help?

    Sub ash3angelz()
    Dim x As Long, y As Long, z As Long, i As Long, w
    ReDim w(2 To Range("X" & Rows.Count).End(3).row)
    For i = LBound(w) To UBound(w)
    x = Len(Cells(i, "X"))
    Select Case x
    Case Is = 10
    Range("W" & Rows.Count).End(3)(2) = Left(Cells(i, "X"), x)
    Case Is > 10
    Cells(i, "X").Select
    y = x / 10
    z = 0
    Do Until y = 0
    Range("W" & Rows.Count).End(3)(2) = Left(Right(ActiveCell, Len(ActiveCell) - z), 10)
    z = z + 10
    y = y - 1
    Loop
    End Select
    Next i
    End Sub

  6. #6
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: Copy 10 digits in a numbers and paste to another column

    In Column w:

    =LEFT(TEXT(X1,"0"),10)

  7. #7
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    Hi John,

    It's not copying the data in Column X

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    When I tested it on your sample, it copied it? Also, I admit some of your data is off. Although I assumed that each cell could be divided evenly by ten, when I run a Len(cell) for the X Column I'm getting some cells with an extra character (ie 21, 32 ect.). This throws the macro off. However, when you do a visual character count I get (20, 30 ect.)

  9. #9
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    Opps my fault, i copied the code in wrong sheets.

    Its perfect the only thing left is which i forgot to quote the finish product should looks like this

    column V column w

    1 10 digits
    10 digits
    2 10 digits
    3 10 digits
    4 10 digits
    10 digits

    for every 10 digits in a row should be across in column v

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    Can you provide a sample with how it would look before and after?

  11. #11
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    Capture.PNG


    the outcome should looks like
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    Try:

    Sub ash3angelz()
    Dim x As Long, y As Long, z As Long, i As Long, w
    ReDim w(2 To Range("X" & Rows.Count).End(3).row)
    For i = LBound(w) To UBound(w)
    x = Len(Cells(i, "X"))
    Select Case x
    Case Is = 10
    Range("W" & Rows.Count).End(3)(2) = Left(Cells(i, "X"), x)
    Case Is = 21
    Range("W" & Rows.Count).End(3)(2) = Left(Cells(i, "X"), 10)
    Range("W" & Rows.Count).End(3)(2) = Right(Cells(i, "X"), 10)
    Case Is = 32
    Range("W" & Rows.Count).End(3)(2) = Left(Cells(i, "X"), 10)
    Range("W" & Rows.Count).End(3)(2) = Left(Right(Cells(i, "X"), 22), 11)
    Range("W" & Rows.Count).End(3)(2) = Right(Cells(i, "X"), 10)
    End Select
    Next i
    End Sub

  13. #13
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    its good, however i need to have space for every invoice

    sample - lets pretend the 1 digit is equal to 10

    starting row should remain and only leave space for every 10 digit numbers or copy to the next same with 2nd starting row first 10 digit across the 2nd starting row then it will insert a row then paste the other 10 digits

    invoice 1 - 1
    _________2
    invoice 2 - 1
    invoice 3 - 1
    ________2
    ________3
    invoice4 1
    _________2

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    Not sure I follow you? That's the reason for the result sheet.

    Sub ash3angelz()
    Dim x As Long, y As Long, z As Long, i As Long, w
    ReDim w(2 To Range("X" & Rows.Count).End(3).row)
    For i = LBound(w) To UBound(w)
    x = Len(Cells(i, "X"))
    Select Case x
    Case Is = 10
    Range("W" & Rows.Count).End(3)(3) = Left(Cells(i, "X"), x)
    Case Is = 21
    Range("W" & Rows.Count).End(3)(3) = Left(Cells(i, "X"), 10)
    Range("W" & Rows.Count).End(3)(3) = Right(Cells(i, "X"), 10)
    Case Is = 32
    Range("W" & Rows.Count).End(3)(3) = Left(Cells(i, "X"), 10)
    Range("W" & Rows.Count).End(3)(3) = Left(Right(Cells(i, "X"), 22), 11)
    Range("W" & Rows.Count).End(3)(3) = Right(Cells(i, "X"), 10)
    End Select
    Next i
    End Sub

  15. #15
    Registered User
    Join Date
    03-10-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    85

    Re: Copy 10 digits in a numbers and paste to another column

    I have attached the result and raw - hope this will help

    THanks
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy 10 digits in a numbers and paste to another column

    This places the results from Columns "D" and "E" into "A" and "B". Per your sample Results.

    Sub ash3angelz()
    Dim x As Long, y As Long, z As Long, i As Long, w
    ReDim w(2 To Range("E" & Rows.Count).End(3).row)
    For i = LBound(w) To UBound(w)
    x = Len(Cells(i, "E"))
    Select Case x
    Case Is = 10
    Range("B" & Rows.Count).End(3)(2) = Left(Cells(i, "E"), x)
    Range("A" & Rows.Count).End(3)(2) = Cells(i, "D")
    Case Is = 21
    Range("A" & Rows.Count).End(3)(2) = Cells(i, "D")
    Range("B" & Rows.Count).End(3)(2) = Left(Cells(i, "E"), 10)
    Range("B" & Rows.Count).End(3)(2) = Right(Cells(i, "E"), 10)
    Range("A" & Rows.Count).End(3)(2) = " "
    Case Is = 32
    Range("A" & Rows.Count).End(3)(2) = Cells(i, "D")
    Range("B" & Rows.Count).End(3)(2) = Left(Cells(i, "E"), 10)
    Range("A" & Rows.Count).End(3)(2) = " "
    Range("B" & Rows.Count).End(3)(2) = Left(Right(Cells(i, "E"), 22), 11)
    Range("A" & Rows.Count).End(3)(2) = " "
    Range("B" & Rows.Count).End(3)(2) = Right(Cells(i, "E"), 10)
    Range("A" & Rows.Count).End(3)(2) = " "
    End Select
    Next i
    End Sub

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

    Re: Copy 10 digits in a numbers and paste to another column

    Try
    Sub test()
        Dim a, b, i As Long, n As Long, m As Object
        With Range("x2", Range("x" & Rows.Count).End(xlUp))
            a = .Value
            ReDim b(1 To 1000, 1 To 1)
            With CreateObject("VBScript.RegExp")
                .Global = True
                .Pattern = "\d{10}"
                For i = 1 To UBound(a, 1)
                    For Each m In .Execute(a(i, 1))
                        n = n + 1: b(n, 1) = m
                Next m, i
            End With
            .Columns(0).Resize(n).Value = b
        End With
    End Sub

+ 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. Excel copy two numbers between specific column and paste in next sheet.
    By visha_1984 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-15-2015, 05:41 AM
  2. Macro to find numbers in column and copy/paste to other sheet
    By maxbeard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2013, 11:28 AM
  3. compare 2 different numbers and copy the last 3 digits.
    By Aranell in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-28-2013, 05:04 AM
  4. [SOLVED] Copy paste rows (with numbers under column A) from one sheet to another
    By sn79 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-04-2013, 04:50 PM
  5. [SOLVED] Copy certain values (9 digits, numbers only) from range
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-11-2012, 12:24 PM
  6. Insert Digits Into A Column of Numbers
    By grayfox in forum Excel General
    Replies: 4
    Last Post: 02-16-2008, 03:30 PM
  7. Replies: 3
    Last Post: 02-27-2007, 08:46 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