+ Reply to Thread
Results 1 to 12 of 12

VBA script required for extracting the clients from one sheet and splitting industry wise

  1. #1
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    VBA script required for extracting the clients from one sheet and splitting industry wise

    Hi Experts,

    I am newbie to Excel VBA. So I request your help in a VBA script.
    I am actually having lot of clients in column "C"and their details in the same row in a sheet. I have a task to split there clients, industry wise and put it into separate sheets.
    For example:Telecom client name in column "c". This has to be extracted and put into a new sheet "telecom" and copy all the details of tht client in the new sheet. This way i have multiple clients in different rows.Below is the script I have written a for one client, but muliple clients script is required. Please help.

    Sub SearchForString()

    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer

    On Error GoTo Err_Execute

    'Start search in row 2
    LSearchRow = 1

    'Start copying data to row 2 in Sheet3 (row counter variable)
    LCopyToRow = 1

    While Len(Range("D" & CStr(LSearchRow)).Value) > 0

    'If value in column D = "AIRCEL", copy entire row to Sheet2
    If Range("D" & CStr(LSearchRow)).Value = "AIRCEL" Then

    'Select row in Sheet1 to copy
    Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
    Selection.Copy

    'Paste row into Sheet3in next row
    Sheets("Sheet3").Select
    Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
    ActiveSheet.Paste

    'Move counter to next row
    LCopyToRow = LCopyToRow + 1

    'Go back to Sheet1 to continue searching
    Sheets("Sheet1").Select

    End If

    LSearchRow = LSearchRow + 1

    Wend

    'Position on cell A1
    Application.CutCopyMode = False
    Range("A1").Select

    MsgBox "All matching data has been copied."

    Exit Sub

    Err_Execute:
    MsgBox "An error occurred."

    End Sub

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi nagabhn

    Welcome to the Forum!!

    Please use Code Tags around any Code you post.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I'd suggest Filtering your Worksheet on each Industry Code then copy the Visible Cells to a new Worksheet. This all can be automated so as to happen on a Button Click.

    If you need help with the Code please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet that demonstrates what you wish the output to be.

    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 "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    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 Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    Post Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi John,

    Thanks for the guidance.
    Attached are the files which is currently existing(Sample Excel Report)and also required report (Reqd Output report). Hope this helps. Attaching the sample code.


    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi nagabhn

    Are there additional Industries besides these? Is the Industry Name actually included in Column 1?
    A
    17
    Telecom
    18
    Manufacturing
    19
    Healthcare
    20
    Energy
    21
    Transport

  5. #5
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi John,
    Thanks for the reply.
    No. Its not specified in any column. That is the actual problem. But I have manually created a industry split excel file in which Column A and B specifies the account versus the industry.

  6. #6
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    Smile Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Missed to attach the sample Industry-mapping file. Attaching the same in this reply.
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Try the attached
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi Jindon,

    Thanks for your macro.This works for the sample report which I have provided, as you have split the "Telecom Account1" into Telecom Industry and created a new sheet.
    May be my example is wrong. In actuals, I have the exact company names which will never say its telecom or healthcare industry,etc. in any column.
    But I need to split the accounts industry-wise by pointing to that industry-mapping file. Their i have specified all the account names in Column A and relevant industry in Column B of same row. Hope this is clear now. Kindly revert.
    Thanks in advance.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    If you are talking about the data which we can not even imagine, no one can help you.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi nagabhn

    This Code is in the attached File "Industry-Mapping". The Code runs from this file with CTRL + x. The Code will ask you which File to open. Place both Files in the SAME Folder.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-06-2014
    Posts
    8

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi John,

    I tried your script which is perfect for the sample report but for my original report, its creating industry specific sheets but only first row is copied to all the sheets.

    Below is the new script with Vlookup function I added which will add a column B in the report and maps with the Account and the industry it belongs to using industry map file. But here I am not able to get the rows counter working properly. It copies the cells leaving lot of rows blank. Please guide me on this.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA script required for extracting the clients from one sheet and splitting industry w

    Hi nagabhn

    I have no ideas for your Code.

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet that demonstrates what you wish the output to be.

    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 "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    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 Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.

+ 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. Group wise Results Required
    By jewnaa in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-17-2014, 10:55 AM
  2. EXCEL: Required MACRO Row Wise Records With The Help Of Delimited Function
    By gaikwad.mm@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2013, 05:24 AM
  3. Replies: 2
    Last Post: 04-24-2013, 01:36 PM
  4. [SOLVED] I want change the data row wise to coloum wise & coloumn wise to row wise.
    By satputenandkumar0 in forum Excel General
    Replies: 3
    Last Post: 12-20-2012, 08:34 AM
  5. Script help required
    By khalid79m in forum Excel General
    Replies: 2
    Last Post: 01-08-2007, 10:17 AM

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