Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Macro to copy data containing numeric values

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0

    Macro to copy data containing numeric values

    I would like a macro to copy data containing numeric values from Col K to J for eg 4201K, W4250 etc

    I am battling to upload the sample data where I highlighted the numeric data in Col K that must be copied to Col J


    I have code to do this, but it does nothing



    Code:
     Sub Copy_Data()
    Dim sh As Worksheet, lr As Long, rng As Range, c As Range
    Set sh = Sheets(1)
    lr = sh.Cells.Find("*", sh.Range("A1"), xlValues, xlPart, xlByRows, xlPrevious).Row
    Set rng = sh.Range("K2:K" & lr)
        For Each c In rng
            If IsNumeric(Left(c.Value, 1)) Then
                c.Copy sh.Cells(Rows.Count, "J").End(xlUp)(2)
            End If
        Next
    End Sub
    Your assistance in resolving this is most appreciated
    Last edited by Flupsie; 04-05-2014 at 07:28 AM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Missed the attachment
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0
    Hi Excel Fox

    After I select Manage attachments, I select browse, Upload data and add files and after waiting 10 minutes , it is still trying to upload a 9 kb file. It would be appreciated if you could assist me

    Flupsie

  4. #4
    Senior Member alansidman's Avatar
    Join Date
    Apr 2012
    Posts
    125
    Rep Power
    14
    You are defining last row using the data in column A. Does Column A have any data in it?

    I modified your code slightly, made sure that there was data in column A and it works.


    Code:
    Sub Copy_Data()
    Dim sh As Worksheet, lr As Long, rng As Range, c As Range
    Set sh = Sheets(1)
    lr = sh.Range("A" & Rows.Count).End(xlUp).Row
    Set rng = sh.Range("K2:K" & lr)
        For Each c In rng
            If IsNumeric(Left(c.Value, 1)) Then
                c.Copy sh.Cells(Rows.Count, "J").End(xlUp)(2)
            End If
        Next
    End Sub

  5. #5
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0
    Hi Alansidman

    Thanks for the help, much appreciated. For some unknown reason , I cannot upload my sample data. I select manage attachments> add files> Browse to select the workbook> upload data, but the files are not uploaded. It may have to do with a setting on my PC. It would be appreciated if you can assist

    The macro is copying the numeric data from Col K to Col J but after the last item in Col J. What I want the macro to do, is that where there is a number value for eg 2507K in K5 then thismust be copied to J5 etc

    Your assistance in this regard is most appreciated

  6. #6
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Flupsie, what is the file type that you are uploading?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  7. #7
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Can you upload the file on to any filesharing site, and post the link here?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  8. #8
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0
    Hi Excel Fox. It is an xlsb file. I selected manage attachments> add files> Browse to select the workbook> upload data, but the files are not uploaded

    It may have to do with Internet security or possibly my MacAfee ACG that is causing the problem

    I am busy downloading drop box and will post the link soon

    Flupsie
    Last edited by Flupsie; 04-05-2014 at 07:45 PM.

  9. #9
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0
    Hi Excel Fox & Alan

    Please find link to drop box below

    https://www.dropbox.com/s/86kl3jyctw...ic%20Data.xlsx

    Flupsie

  10. #10
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Try this

    Code:
    Sub ExcelFox()
    
        Dim rng As Range
        Dim rngEach As Range
        With Worksheets("Sheet1")
            Set rng = .Range("K2", .Cells(.Rows.Count, "K").End(xlUp))
        End With
        For Each rngEach In rng
            If HasNumber(rngEach.Value) Then
                rngEach(, 0).Value = rngEach.Value
            End If
        Next rngEach
    End Sub
    
    Private Function HasNumber(varValue As Variant) As Boolean
    
        HasNumber = Evaluate("MAX(IFERROR(FIND({""0"",""1"",""2"",""4"",""5"",""6"",""7"",""8"",""9""},""" & varValue & """),0))")
        
    End Function
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Replies: 0
    Last Post: 04-20-2013, 10:07 AM
  2. Macro to copy data in specific Columns
    By Howardc in forum Excel Help
    Replies: 0
    Last Post: 04-19-2013, 10:42 AM
  3. Extracting Numeric Values From Alphanumeric Text
    By Safal Shrestha in forum Excel Help
    Replies: 3
    Last Post: 03-21-2013, 12:04 PM
  4. Macro to copy data from a set of excel files
    By Sreejesh Menon in forum Excel Help
    Replies: 5
    Last Post: 11-15-2012, 11:17 AM
  5. Replies: 2
    Last Post: 11-08-2012, 01:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •