+ Reply to Thread
Results 1 to 15 of 15

Macro to check lenght of characters and merge cells

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Macro to check lenght of characters and merge cells

    Hello, guys!

    I am trying to do a macro that checks if the length of a row is more than 3 characters, if that's correct - merge that field with another 45 into a third one. However, I really got lost so I'd need your help. This is what I got so far.

    Please Login or Register  to view this content.
    Question is how can I specify these 45 rows to be merged with that "M1"?
    Got really lost...
    Attached Files Attached Files
    Last edited by hit1234; 04-08-2013 at 08:26 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Macro to check lenght of characters and merge cells

    Hi and welcome to the forum,

    According to forum rule number 3, codes must be wrapped with code tags, and we can't help you before you fix it.

    Cheers,
    If I have helped, Don't forget to add to my reputation (click on the star icon below the post).
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved).
    Use code tags when posting your code.

  3. #3
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    Thank you very much!

    I was wondering 5 minutes ago if I can use inline code tag or something.

    Kind regards,

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to check lenght of characters and merge cells

    It will be good if you explain with the help of a sample file. Just dummy data will do, as long as the format matches the original file.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to check lenght of characters and merge cells

    Thank you Mayda.

    Since hit1234 is a newbie to the forum, i added them for him.

  6. #6
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    Thank you very much once again.

    Just spent a couple of minutes to get to know the posting system, quite nice indeed! I will stick to them in future.

    I just uploaded the file with dummy data, it was my bad for not posting one, thank you for pointing that out.

    So the comment could be spread over several rows, and I would like to merge them together based on country characters. For instance, if the country code is greater than 3 characters(e.g. chn), it will merge all the fields containing information about user's comment.

  7. #7
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Macro to check lenght of characters and merge cells

    Cheers arlu

    @hit1234:
    If you want to merge for example the range A1:B5 you can use this simple line of code:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    First I have to check if the data is less than 3 characters and then merge, otherwise there could be duplicates cause of incorrect data input.

  9. #9
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Macro to check lenght of characters and merge cells

    You can use the VBA.len function to check the length of the string in the cell.

  10. #10
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    Please Login or Register  to view this content.
    Yeah, but I still don't know how paraphrase it.

  11. #11
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Macro to check lenght of characters and merge cells

    Quote Originally Posted by hit1234 View Post
    [CODE]
    Yeah, but I still don't know how paraphrase it.
    What do you mean by that?

  12. #12
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    Struggling with the syntax, I am just reading online trying to get myself familiar with it.

  13. #13
    Forum Contributor Mayda89's Avatar
    Join Date
    09-13-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Macro to check lenght of characters and merge cells

    The example you wrote was correct.

  14. #14
    Registered User
    Join Date
    11-21-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to check lenght of characters and merge cells

    Fixed it with: =IF(LEN(M5)>=5;"0";CONCATENATE(((M5)&(N5))))

    Would be nice if I get my head around that VBA macro thingy though.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to check lenght of characters and merge cells

    You mean you want to convert your formula into vba?

+ 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