Consulting

Results 1 to 3 of 3

Thread: Solved: Cut and Paste to different cell

  1. #1

    Solved: Cut and Paste to different cell

    Hi! Please help with this problem: I have a sheet with five columns in col B I have cells with both text and numbers at varying intervals. I want to run a macro that will find each number then cut and paste it one row above and two columns over. Heres what I have:

    [VBA]
    Sub newtry()

    Range("B2").Select

    Dim testvar As Object
    Set testvar = Range("B2")
    Dim numericcheck As Boolean
    numericcheck = IsNumeric(testvar)

    Do Until IsEmpty(ActiveCell.Offset(0, 3))
    If numericcheck = False Then
    testvar.Select.Cut.Offset(-1, 2).Paste
    ActiveCell.Offset(2, -2).Select
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Loop



    End Sub
    [/VBA]

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum! When pasting code, please paste between VBA code tags.

    Select and Activate are often not needed and can slow your code execution. Even the cut/copy will do that so it slows down, see my speed routines in the kb.

    [VBA]Sub newtry()
    Dim r As Range, c As Range
    Set r = Range("B2", Range("B" & Rows.Count).End(xlUp))
    For Each c In r
    If IsNumeric(c) Then c.Cut c.Offset(-1, 2)
    Next c
    End Sub[/VBA]

  3. #3
    Wow! That was so seamless. New to VBA and the forum, I'll be sure post correctly next time. Thank you for a fast and perfect response!

Posting Permissions

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