+ Reply to Thread
Results 1 to 10 of 10

making labels/cutting and pasting

  1. #1
    Registered User
    Join Date
    10-27-2011
    Location
    London. England
    MS-Off Ver
    Excel 2007
    Posts
    5

    making labels/cutting and pasting

    Hello

    I was wondering if anyone could help me as I am stuck with a problem at work. Basically I have customer names and addresses in an excel 2007 spreadsheet, and I want to move all the "Mr" and "Mrs" etc. up three rows as it they are in the wrong place. There are tons of these to do so I was trying to use VBA but am awful at programming. Here it is what I have now:


    Private Sub Workbook_Open()

    Worksheets("Sheet1").Cells

    Dim Mr As String
    Dim Mrs As String
    Dim Miss As String
    Dim Ms As String
    strCellValue = (cell.Value)

    Mr = "MR"
    Mrs = "MRS"
    Miss = "MISS"
    Ms = "MS"

    If strCellValue = Mr Then
    ActiveCell.Offset(-3, 0).Activate

    ElseIf strCellValue = Mrs Then
    ActiveCell.Offset(-3, 0).Activate

    ElseIf strCellValue = Miss Then
    ActiveCell.Offset(-3, 0).Activate

    ElseIf strCellValue = Ms Then
    ActiveCell.Offset(-3, 0).Activate

    End If

    End Sub



    Could someone show me what I've done wrong? It's obviously mish-mashed code I've formed whilst attempting to learn how to do this through the internet. I would be so grateful if anyone can help!

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: making labels/cutting and pasting

    Hi,

    Please edit your post to include code tags as per the forum rules.

    I think it would also help greatly to see a sample workbook showing a before and after of what you are trying to achieve.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

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

  3. #3
    Registered User
    Join Date
    10-27-2011
    Location
    London. England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: making labels/cutting and pasting

    oops sorry! I have never programmed or used any of these forums before so hopefully this is what you meant:

    Please Login or Register  to view this content.
    And I'm afraid I'm not allowed to post the work book, but say these details were in 3 cells A2-A4, and I wanted the "MR" to be in cell A1:

    Peter Smith
    London
    MR

    I just wanted to solve the problem "in all cases where 'MR'/'MRS'/'MISS'/'MS' appears, cut this value from the cell it is in and paste in the cell in the same column, 3 rows above it.


    Thank you for the forum advice!
    Attached Files Attached Files
    Last edited by s_pap; 10-27-2011 at 07:13 AM. Reason: mistaken tags

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: making labels/cutting and pasting

    Have a look at my signature as to what I mean by code tags. You can edit your existing posts by clicking the edit button.

    I appreciate you can't post people's real addresses but it would be a great help to see a workbook with the actual layout of a few fictitious examples.

    Dom

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: making labels/cutting and pasting

    Try this:

    Please Login or Register  to view this content.

    Dom

  6. #6
    Registered User
    Join Date
    10-27-2011
    Location
    London. England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: making labels/cutting and pasting

    That hasn't done anything when I run it, but at least there are no errors or anything like with my code. Just to clarify I am not being a total idiot, I do run it by just selecting MACROS>selecting name of the macro>Run right? Thank you so much for your swift replies and help.

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: making labels/cutting and pasting

    No problem, thanks for the sample.

    The code should really go in a regular vba module (although it shouldn't matter in this case).

    I've modified it to take account of the values being in either upper or lower case.

    Please Login or Register  to view this content.

    Dom

  8. #8
    Registered User
    Join Date
    10-27-2011
    Location
    London. England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: making labels/cutting and pasting

    I put it in a regular vba module and ran it, but now an error came up "Run-time error '1004' Application-defined or object-defined error", and it highlighted the line

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: making labels/cutting and pasting

    I assume you have a blank row at the top of your data for the first item to move into?

    Dom

  10. #10
    Registered User
    Join Date
    10-27-2011
    Location
    London. England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: making labels/cutting and pasting

    ooh for some reason I ran it again, and despite the error message coming up again, the problem got fixed yess, thank you that was so helpful!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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