+ Reply to Thread
Results 1 to 16 of 16

Need assistance on Macro (splitting the data)

  1. #1
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Post Need assistance on Macro (splitting the data)

    Hey there,

    Attached is the sample data for reference.

    The workbook contains 2 sheets i.e., Raw data and Allocation sheet.
    This is a chargeback allocation that I need to allocate to the team. My query is that... There is a column called "site" (Column L). That needs to be split according to the number I enter in the "Allocation" sheet. For instance, if the total data contains 400 rows and I need a macro where data should split based on the "site" column i.e., HYD 100 and BLR 200. So, whatever number I enter in the "Allocation" sheet should break accordingly, and the remaining data can be deleted.

    Please review and do needful. I really appreciate any help you can provide.

    Sample file.xlsx

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need assistance on Macro (splitting the data)

    the remaining data can be deleted.
    It means that the LAST rows out of 100 for HYD and the LAST rows out of 200 for BLR will be deleted?
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Need assistance on Macro (splitting the data)

    Assumes both sites exist...As per sample file requirement...Keep 63 BLR and keep 64 HYD if that much exists...If not...leave as is
    Change red snippet to Delete after testing to see if code works...
    Please Login or Register  to view this content.
    Last edited by Sintek; 12-26-2022 at 01:58 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hi PCI,
    It means if the data is 300 and I need only 200 i.e., BLR 100 and HYD 100 so remaining 100 can be deleted. So, basically whatever the number I enter should only display in Raw data.

  5. #5
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hey Sintek,

    Thanks for looking into the query.
    I guess the code was not working fine. It was highlighting with yellow some data but it's not splitting the data according to the number I enter in sheet 2 ("Allocation"). Can you please review it and advise with the new/modified code?

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Need assistance on Macro (splitting the data)

    Hello. I ask you:

    a) You already commented on the number of rows to delete but: And what rows should be deleted? What is the elimination criteria?...

    b) It seems to me that the best thing would be for you to take the workbook from Post #1 and add a third sheet in which you show us the expected final result...
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Need assistance on Macro (splitting the data)

    I guess the code was not working fine. It was highlighting with yellow some data but it's not splitting the data according to the number I enter in sheet 2 ("Allocation").
    I purposely did that and explained above why...The yellow highlighted is the data that will be deleted keeping only the required allotted lines...
    I wanted you to first see if this is what you were wanting...If so, you had to change the highlight code snippet to delete, which will leave only the allotted lines remaining...
    Change this...
    Please Login or Register  to view this content.
    to...
    Please Login or Register  to view this content.
    By doing this...Only the allotted lines that you stipulated would remain...The rest would be deleted...
    If this is not what you wanted, then I suggest, as per beyond Excel, uploading a sample file showing a before | after expected scenario so that we can see exactly what it is you would want to achieve...
    Last edited by Sintek; 12-27-2022 at 02:45 AM.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,633

    Re: Need assistance on Macro (splitting the data)

    See below code.
    PHP Code: 
    Option Explicit
    Sub allocate
    ()
    Dim lr&, i&, cell As RangeBLRcount&, HYDcount&, site
    With Sheets
    ("Allocation")
        
    BLRcount = .Range("C4")
        
    HYDcount = .Range("D4")
    End With
    With Sheets
    ("Raw Data")
        
    lr = .Cells(Rows.Count"L").End(xlUp).Row ' last row with data in column L
        site = .Range("L2:L" & lr).Value ' 
    store column L value into array
        For 
    1 To UBound(site' loop thru column L value, and subtract from total till 0, then delete value
            Select Case site(i, 1)
                Case Is = "BLR"
                    If BLRcount = 0 Then
                        site(i, 1) = ""
                    Else
                        BLRcount = BLRcount - 1
                    End If
                Case Is = "HYD"
                    If HYDcount = 0 Then
                        site(i, 1) = ""
                    Else
                        HYDcount = HYDcount - 1
                    End If
            End Select
        Next
        .Range("L2:L" & lr).Value = site ' 
    copy back site into sheet
        
    .Range("L2:L" lr).SpecialCells(xlBlanks).EntireRow.Delete ' delete blank cells in bulk
    End With
    End Sub 
    Attached Files Attached Files
    Quang PT

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

    Re: Need assistance on Macro (splitting the data)

    Quote Originally Posted by Pawan Sai View Post
    I need a macro where data should split based on the "site" column i.e., HYD 100 and BLR 200. So, whatever number I enter in the "Allocation" sheet should break accordingly, and the remaining data can be deleted.
    You didn't tell us about remaining data for other than HYD/BLR if there are any.
    Simply
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hey Sintek,

    It's my bad...I was not able to understand that before. Very sorry for that. Yea the macro was working fine now. I replaced the code "If X2 - X1 + 1 > Num Then .Rows(X1 + Num & ":" & X2).Interior.Color = vbYellow" with "If X2 - X1 + 1 > Num Then .Rows(X1 + Num & ":" & X2).Delete". This was too perfectly working and meeting all my requirements. Thanks a lot for your quick assistance.

  11. #11
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hey bebo021999,

    Thanks a lot for looking into the query and this code was perfect. Correctly working on the data I enter without any churns. Thank you once again for your assistance.

  12. #12
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hey Jindon,

    This code meets my requirements and working fine. Thanks a lot for your assistance on the query I posted.

  13. #13
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Hey beyond excel,

    Thanks for looking into the query. No, there is no need to have the deleted data. So requested the macro to eliminate the data apart from the number I entered in the table. However, the query got resolved from the above codes mentioned. Thanks for the time for looking into the query.

  14. #14
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Thank You all for your great help. All the codes mentioned by you were working fine.
    Surprisingly, I found many people here to help people with their queries...

    Thanks a lot for everyone for your great assistance on queries.

  15. #15
    Registered User
    Join Date
    09-04-2022
    Location
    India
    MS-Off Ver
    Office 16
    Posts
    32

    Re: Need assistance on Macro (splitting the data)

    Resolving the thread as the query was resolved.

    Thank you all once again.

  16. #16
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Need assistance on Macro (splitting the data)

    Quote Originally Posted by Pawan Sai View Post
    Hey Sintek,

    It's my bad...I was not able to understand that before. This was too perfectly working and meeting all my requirements. Thanks a lot for your quick assistance.
    Glad you got it sorted...Tx for rep...Happy Coding...

+ 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. How to add condition in this macro - splitting the data to different files
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-03-2018, 11:06 PM
  2. [SOLVED] assistance to adjust splitting formula in certain column headers which blank cells
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2018, 05:03 AM
  3. [SOLVED] VBA code assistance with splitting of text in a cell.
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-21-2016, 05:11 AM
  4. [SOLVED] Splitting Data-Tweak My Macro
    By votekinky06 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2014, 08:34 AM
  5. Need VBA Macro Assistance - Transpose data
    By matthewjberry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2013, 06:08 PM
  6. Macro for splitting data
    By kamal.mk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2013, 06:40 AM

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