+ Reply to Thread
Results 1 to 10 of 10

Move from one row to specified row and column

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    48

    Move from one row to specified row and column

    Hello
    I made a macro to move one row content to another row and column and after I reinstal some programs, it doesn't work anymore.

    Sub muta()
    
    ' Muta centrul cercului in dreptul ultimei coordonate
    
    Dim Lr As Long, i As Long
    Lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To Lr
        With Range("A" & i)
            If LCase(.Value) Like "of" Then .Cut Destination = .Offset(-5, 10)
        End With
    Next i
    End Sub
    Anyway I want something like this:
    The macro search a row who it content the value "of" and it move the entire row content to the row -5 (up 5 rows) and the column 10
    Then it continues searching to the end of the rows.
    Last edited by RoMarius1981; 10-02-2013 at 04:25 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Move from one row to specified row and column

    Please use code tags with your code as per forum's rule.
    You are missing a couple of lines
    If you start at row 1, you can not go up as row 1 is the first row.
    You can cut an entire row and paste in column 10. You can only paste in column A
    You may not get "of" values if you are missing asterisk from like.
    Cut/delete works well if you loop back ward.

    Sub test()
    
    Dim Lr As Long, i As Long
     Lr = Range("A" & Rows.Count).End(xlUp).Row
     For i = 6 To Lr
        With Range("A" & i)
          If LCase(.Value) Like "of" Then .Rows(i).Cut Destination = .Offset(-5, 10)
        End With
     Next i
     End Sub
    Last edited by AB33; 10-01-2013 at 05:27 AM.

  3. #3
    Registered User
    Join Date
    11-05-2012
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Move from one row to specified row and column

    Dooesn't work.
    Same error at "LCase"

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Move from one row to specified row and column

    I did not say or indicated the code works. It will never work, copying entire row in to different column other than the first column is impossible in excel.
    There are also other reasons for the code not to work. For e.g. like with *.

    Try

    Sub test()
    
    Dim Lr As Long, i As Long
    Application.ScreenUpdating = 0
        With ActiveSheet
            Lr = .Range("A" & .Rows.Count).End(xlUp).Row
            For i = 6 To Lr
                 If LCase(.Cells(i, 1)) Like "of" Then
                   .Rows(i).Copy
                   .Cells(i, 1).Offset(-5, 0).PasteSpecial xlValues
                   .Rows(i).Clear
                 End If
            Next i
         End With
     Application.ScreenUpdating = 0
    End Sub

  5. #5
    Registered User
    Join Date
    11-05-2012
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Move from one row to specified row and column

    I tried
    Nothing
    Still same error at LCase
    And I tell you; this code worked perfectly till I reinstalled office

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Move from one row to specified row and column

    And I tell you; this code worked perfectly till I reinstalled office
    Ensure there are no missing references in the Visual Basic Editor (VBE) via these four steps:

    1. If it isn't already open the file with the macro and go into the VBE (Alt + F11)
    2. From the Tools menu select References
    3. Scroll down the list of Available References and unclick any that have MISSING in their name
    4. After each reference with MISSING in their name have been unticked, click OK and then from the File menu click Close and Return to Microsoft Excel

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Move from one row to specified row and column

    Could you please attach your sample in order to test it?

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Move from one row to specified row and column

    AB33 asked for you to use code tags around your code. Is there a particular reason that you ignored his request? Pls do it in your code in your first post!
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  9. #9
    Registered User
    Join Date
    11-05-2012
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Move from one row to specified row and column

    Here it is the file
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Move from one row to specified row and column

    As I said, your condition is wrong.
    What is "of"? I could not see any cell in column A, in sheet Main? The code will loop through column A, but will return nothing as there is no row to match.
    I see words like comman,ID, figures and etc, but not a word with "of"? on it.
    It has to be like a asterisk then the word you are looking for and then possibly another asterisk

+ 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: 4
    Last Post: 09-23-2013, 06:19 PM
  2. [SOLVED] Seperate data in column A that has specific word and move to column B or C or D
    By jachbo in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 09-05-2013, 09:08 PM
  3. [SOLVED] Why does the formula move when I move the column
    By ag6 in forum Excel General
    Replies: 5
    Last Post: 04-21-2012, 04:56 PM
  4. Copy/move a word from a cell in a column to another column and autofill
    By excelaspire0219 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2009, 03:54 PM
  5. Replies: 2
    Last Post: 12-27-2005, 06:30 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