+ Reply to Thread
Results 1 to 5 of 5

VBA insert/delete rows to accommodate exact number of rows from incoming data

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    2

    Unhappy VBA insert/delete rows to accommodate exact number of rows from incoming data

    Hi,

    I am a newbie here and just started working on basic excel vba. I have an issue about adjusting rows automatically.

    Situation: I have 4 sheets nameld Sheet1,Sheet2,Sheet3 and Sheet4. Sheet1,2,3 with datas on Column A and B (List of Students) for Boys and Girls respectively.
    Sheet4 has datas within named ranges "Class1" and "Class2" lined up in Column B. The list of boys and girls datas from Sheet1/2/3 are dynamic with rows of datas range from 10 to +50 students.

    Problem: Adjusting the rows automatically is the problem. Example, if the list of students from Boys has 10 rows while "Class1" has 20 rows then "Class1" should be trimmed automatically to 10 rows to accommodate the datas exactly. This goes the same with Class2. Auto insert or delete of rows sort of.

    Ideally, Dynamic ranges applies but with one named range in one column only. I have two named ranges lined up in Sheet4 Col B with other datas in between and this is where the issue start.

    This is the code i have so far, it works with copying and filling. I dont have the vba for auto adjustment of rows whether insert/delete based on the incoming datas from Sheet1,2 or 3.

    Please Login or Register  to view this content.
    Note: "ClassB" and "ClassG" are just the names of of the 1st Cells in both named ranges "Class1" and "Class2".

    Sorry for the long story, I hoped i did not confused you so much.

    Please help me! Tks
    Iloco
    Last edited by iloc; 11-12-2012 at 06:20 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA insert/delete rows to accommodate exact number of rows from incoming data

    Hi, iloc,

    I have two named ranges lined up in Sheet4 Col B with other datas in between and this is where the issue start.
    It might be a good idea to give us a look at your workbook with an example of the wanted output.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    11-07-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA insert/delete rows to accommodate exact number of rows from incoming data

    Class Record.xlsm

    Hi Holger,

    Here is the attached sample.

    Just click on button "deped" and select/click no.1. Hence, you'll find in column B the button "Change name" colored yellow, this will show a drop menu to select from 3 sheets where this
    list of students should come from. It is working alright but as you notice if the list(rows)
    changed from the source of datas....this named rows in column B does not follow exactly (no vbacode yet) that I cant think of. This is my problem.

    Tks for looking into this.

    Iloc

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA insert/delete rows to accommodate exact number of rows from incoming data

    Hi, Iloc,

    regarding your question about the filling for teh rows I would suggest to wotk with ranges for the maximum of boys and girls and hide the rows which will not be needed. To get there I changed the numbers (only on Sheet "V - Dandelion") to show the maxiumum of entries for either boys or girls.

    The AutoFill for Boys on "English V - Dandelion" could then be written like this:
    Please Login or Register  to view this content.
    I exported most of the forms (I will have to look at thme later on) as well deleted a lot of the sheets (for reason of the file size only) and left only UF5 (where the ranges are to be selected as example).

    Please have a look at the workbook and see if this may help with the problem.

    Ciao,
    Holger
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-07-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA insert/delete rows to accommodate exact number of rows from incoming data

    Tks Holger

    I will just max the range needed and hide rows with no values. Thanks for looking into this.

    Rgds,
    Iloc

+ 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