+ Reply to Thread
Results 1 to 7 of 7

VBA to Concatenate Variable Range

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question VBA to Concatenate Variable Range

    Dear All,
    I have a problem with a worksheet that my company accounting system exports every month.

    Attached : sample of the worksheet.

    In column ( F ) , I need a macro to do the following calculations:
    1- Check for the Title – if it begins with "Cost Center"
    2- Check for the Title – if it begins with "Account Code"
    3- Detect the Range Start just below "Account Code" , and End with the row above "Total"
    4- Concatenate the string written in each row of the range with the string in "Cost Center"

    The Story is:
    Each Month I've this worksheet with hundreds of Cost Centers and subsidiary Account Codes, And to be able to analyze the accounts efficiently I need to concatenate both Cost Centers & Account Codes manually ( as you see coloring sample in the attached file ).
    Which led to wasting many hours , and high risk of error while copying and pasting formulas.

    Your help on this matter will be highly appreciated.
    Best Regards.
    Attached Files Attached Files

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

    Re: VBA to Concatenate Variable Range

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button
    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]

  3. #3
    Registered User
    Join Date
    10-24-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA to Concatenate Variable Range

    Hi Arlette;

    Thanks for your response.

    The code displayed the message box, however no values were registered in the worksheet.

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

    Re: VBA to Concatenate Variable Range

    Did you try it on your sample file or on the original? I ran it on your sample file and it worked.

  5. #5
    Registered User
    Join Date
    10-15-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003/2010
    Posts
    22

    Re: VBA to Concatenate Variable Range

    Try this code:-
    Please Login or Register  to view this content.
    You should install this code in a standard code module (by default "Module1") and remember to save your workbook as macro enables.
    To call the code select SetAccountIDs from the list of macros available from Macros on the Developer tab. Look for Excel Help to enable this tab if you don't have it in your ribbon.

  6. #6
    Registered User
    Join Date
    10-24-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA to Concatenate Variable Range

    Dear Arlette;

    Words can't help me thank you enough.

    My mistake, I've copied the sheet1 to sheet2 in order to compare the results, Now after I've renamed the vba to sheet2 it worked like magic.

    My deepest and sincere regards for you

  7. #7
    Registered User
    Join Date
    10-24-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA to Concatenate Variable Range

    Dear Tartarus;

    Many thanks for your code.

    it's a pleasure to know how much this amazing forum could help.

+ 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