+ Reply to Thread
Results 1 to 10 of 10

parts of macro aren't working

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    parts of macro aren't working

    Hey all,

    Parts of the below macro aren't working. For example, if a name is like this:

    John Smith R, Sr.
    Ann Smith S,


    It's supposed to be replaced with:

    John Smith R
    Ann Smith S


    Please Login or Register  to view this content.
    It doesn't produce any kind of error message. It simply just doesn't get rid of aforementioned undesirable content, despite me clearing telling it to in the macro.

    Thanks for response.
    Attached Files Attached Files
    Last edited by johnmerlino; 12-09-2010 at 11:12 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: parts of macro aren't working

    Assuming from your examples that you want everything after and including the comma to be deleted, a possible solution would be =LEFT(K17,FIND(",",K17)-1)

    ( sorry no VBA man myself)

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: parts of macro aren't working

    Your code isn't ever touching the data, it's just putting formulas into the cells, then replacing the formula with the resulting value. Also, your second assignment statement is wiping out the first. Also, your formulas are always going to refer to cell A1 regardless of what row the new data is on. Maybe you are unclear on exactly how this kind of code works.

    This might be more effective if you modify your VBA to do what you actually want, instead of using VBA to plug in formulas to cells. String manipulation is a little more sophisticated in VBA than what you can do with Excel functions (but only a little).

    Here is a start. It is difficult to do this without seeing sample data. This assumes that the data you're starting with is in column A in the last row, and the cleaned-up version goes into column B. I didn't test it because I don't know exactly what your data looks like. I gleaned this from your formulas.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: parts of macro aren't working

    Thanks for response. It gives me a compile error right away highlighting "Range" in Range.Cells(lngLastRow, 1).Value
    It says "argument not optional"
    Last edited by johnmerlino; 12-09-2010 at 10:40 PM.

  5. #5
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: parts of macro aren't working

    I attached some sample data.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: parts of macro aren't working

    Quote Originally Posted by johnmerlino View Post
    Thanks for response. It gives me a compile error right away highlighting "Range" in Range.Cells(lngLastRow, 1).Value
    It says "argument not optional"
    I'm sorry, in my rush to publish I didn't test. This will compile, and mostly work. I will check it against your test data and provide any needed updates.
    Please Login or Register  to view this content.
    Sheet1 is the name of the sheet with the data. If the code is in the same module as the worksheet with the data you don't need "Sheet1." where it appears.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: parts of macro aren't working

    OK, here's a workbook. Click the button to clean up your data.

  8. #8
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: parts of macro aren't working

    Thanks when I paste the macro into my personal.xlsb, and run the macro from within excel, nothing happens. It appears some kind of button function is executing it.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: parts of macro aren't working

    If you put the macro in PERSONAL.XLSB you will have to rewrite it. It is written to execute in the same book that contains the data. Will revisit when I have some time.

  10. #10
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: parts of macro aren't working

    Thanks for response.

    This seems to have worked:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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