+ Reply to Thread
Results 1 to 7 of 7

Need some VBA ideas for inserting rows

  1. #1
    Forum Contributor
    Join Date
    05-11-2020
    Location
    Kansas City
    MS-Off Ver
    Office 365
    Posts
    162

    Need some VBA ideas for inserting rows

    I am building a staffing workbook that will be used by some fellow Employees that tend to not have much excel knowledge. I want to use the "STAFFING DATA" sheet to update the Days_Seniority, Eves_Seniority and Mids_Seniority sheets. I have created an "Update Position Needs" button on the "STAFFING DATA" sheet that I would like to use to insert/ remove lines to their related Position on the other sheets as well as the "STAFFING DATA" sheet. I have tried to look for VBA online to help, but I must not be looking under the correct criteria. Any help in this matter would be greatly appreciated.

    Thank you,

    Adam
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Need some VBA ideas for inserting rows

    Your data in the sample workbook is confusing me .

    In the date column you have :
    A. dd-mm-yy format, and which is not so clear mm/dd/yyyy or dd/mm/yyyy.

    Example :
    10-03-86
    8/3/2017
    7/25/2019

    B. Then in STAFFING DATA sheet, the value is not consistent with your table.
    Example :
    in Table sheet (to populate the combobox) : -----------> in Staffing Data Sheet:
    GROUP LEAD ------------------------------------------------> GROUP LEADER
    ASST GROUP LEAD -----------------------------------------> ASST. GROUP LEADER
    PROCESS TECH ---------------------------------------------> PROCESS TECHS
    PROCESS TECH (TR) ---------------------------------------> PROCESS TECHS (TRAINING)

    I'm trying to see whether I can help or not,
    but then after I found the text is not consistent (especially in point-B),
    sorry I have to give up .
    Last edited by karmapala; 06-30-2020 at 04:06 AM.

  3. #3
    Forum Contributor
    Join Date
    05-11-2020
    Location
    Kansas City
    MS-Off Ver
    Office 365
    Posts
    162

    Re: Need some VBA ideas for inserting rows

    karmapala,

    I am sorry for the discrepancies. This project started out as a small single sheet that would help me align Employees and add/ switch them around. My Boss was scouring our shared
    drive and found it and asked that I make it a lot more complicated. I have been reading some books on VBA and using the things I was able to understand to make some sort macros etc..
    Once my Boss saw I was able to create some minor code, he asked that I combine several sheets and create this huge project that is well beyond my ability. I have adjusted all the
    discrepancies and would appreciate it if you had the time to help me out!

    Thank you,

    Adam
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Need some VBA ideas for inserting rows

    Please have a look to the attachment.
    Just click your Update Position Needs button on sheet STAFFING DATA,
    select the combo box and fill the text-box with number.

    Although I'm still don't know how exactly you want the result,
    the code is only based on my guess as follow :

    Pre-condition:
    in STAFFING DATA sheet, the yellow highlighted cell is an indicator on how many rows on each PositionTitle,
    and that also the same rows on sheet Days, Eves and Mids.



    Take an example in your sample workbook, the PROCESS TECH yellow highlighted cell is 4. So...:
    there are 4 rows under PROCESS TECH in sheet STAFFING DATA, and
    there are 4 PROCESS TECH rows (with number 1 to 4 on the left) on Sheet Days, Eves and Mids,
    disregarding whether there is a blank cell in that 4 rows or not.

    Userform: (example)
    the user select PROCESS TECH value in the ComboBox....

    If A:
    the user fill the TextBox with number 6, after the user click UPDATE button then the expected result is :
    in STAFFING DATA sheet, now there are 6 rows under the PROCESS TECH and it's yellow highlighted cell is 6.
    It happen also in sheet Days, Eves and Mids, there are 6 PROCESS TECH rows (with number 1 to 6 on the left).
    The sheet Days, Eves and Mids will also have all the names respectively with the names (if any) under Days/Eves/Mids column in sheet STAFFING DATA.

    If B:
    the user fill the TextBox with number 2, after the user click UPDATE button then the expected result is :
    in STAFFING DATA sheet, now there are 2 rows under the PROCESS TECH and it's yellow highlighted cell is 2.
    (it won't bother to the existed names (under the PROCESS TECH) before... so if before there are 4 names, the last 2 names will be gone)
    It happen also in sheet Days, Eves and Mids, there are 2 PROCESS TECH rows (with number 1 to 2 on the left).
    (also it won't bother to the existed names (of the PROCESS TECH) before... so if before there are 4 names, the last 2 names will be gone)
    The sheet Days, Eves and Mids will also have all the names respectively with the names (if any) under Days/Eves/Mids column in sheet STAFFING DATA.

    If C:
    nothing fill in the TextBox, after the user click UPDATE button then the expected result is :
    nothing happen to the row, but only the names in sheet Days, Eves and Mids will be "updated" based on sheet STAFFING DATA and the selected ComboBox value.
    disregarding whether there is any update to the names or not in sheet STAFFING DATA.
    For example if C.... in sheet STAFFING DATA:
    the current GROUP LEAD is Bardia Rajaei under Days column
    the current GROUP LEAD is Adam Newton under Eves column
    the current GROUP LEAD is Jason Stithem under Mids column

    Later on, in sheet STAFFING DATA it change to bla, bli and ble respectively.
    The need is only to update the name in sheet Days, Eves and Mids...
    So, in the userform, just select the "GROUP LEAD" value in ComboBox,
    and leave the TextBox empty, then click the UPDATE button,
    the sheet Days Group Lead name now is bla
    the sheet Eves Group Lead name now is bli
    the sheet Mids Group Lead name now is ble

    So that's my guess on what you want for the result.
    Attached Files Attached Files
    Last edited by karmapala; 07-01-2020 at 05:01 AM.

  5. #5
    Forum Contributor
    Join Date
    05-11-2020
    Location
    Kansas City
    MS-Off Ver
    Office 365
    Posts
    162

    Re: Need some VBA ideas for inserting rows

    Thank you for your help! That works exactly how I wanted it to. I really appreciate your help on this one.

  6. #6
    Forum Contributor
    Join Date
    05-11-2020
    Location
    Kansas City
    MS-Off Ver
    Office 365
    Posts
    162

    Re: Need some VBA ideas for inserting rows

    Quote Originally Posted by karmapala View Post
    Please have a look to the attachment.
    Just click your Update Position Needs button on sheet STAFFING DATA,
    select the combo box and fill the text-box with number.

    Although I'm still don't know how exactly you want the result,
    the code is only based on my guess as follow :

    Pre-condition:
    in STAFFING DATA sheet, the yellow highlighted cell is an indicator on how many rows on each PositionTitle,
    and that also the same rows on sheet Days, Eves and Mids.



    Take an example in your sample workbook, the PROCESS TECH yellow highlighted cell is 4. So...:
    there are 4 rows under PROCESS TECH in sheet STAFFING DATA, and
    there are 4 PROCESS TECH rows (with number 1 to 4 on the left) on Sheet Days, Eves and Mids,
    disregarding whether there is a blank cell in that 4 rows or not.

    Userform: (example)
    the user select PROCESS TECH value in the ComboBox....

    If A:
    the user fill the TextBox with number 6, after the user click UPDATE button then the expected result is :
    in STAFFING DATA sheet, now there are 6 rows under the PROCESS TECH and it's yellow highlighted cell is 6.
    It happen also in sheet Days, Eves and Mids, there are 6 PROCESS TECH rows (with number 1 to 6 on the left).
    The sheet Days, Eves and Mids will also have all the names respectively with the names (if any) under Days/Eves/Mids column in sheet STAFFING DATA.

    If B:
    the user fill the TextBox with number 2, after the user click UPDATE button then the expected result is :
    in STAFFING DATA sheet, now there are 2 rows under the PROCESS TECH and it's yellow highlighted cell is 2.
    (it won't bother to the existed names (under the PROCESS TECH) before... so if before there are 4 names, the last 2 names will be gone)
    It happen also in sheet Days, Eves and Mids, there are 2 PROCESS TECH rows (with number 1 to 2 on the left).
    (also it won't bother to the existed names (of the PROCESS TECH) before... so if before there are 4 names, the last 2 names will be gone)
    The sheet Days, Eves and Mids will also have all the names respectively with the names (if any) under Days/Eves/Mids column in sheet STAFFING DATA.

    If C:
    nothing fill in the TextBox, after the user click UPDATE button then the expected result is :
    nothing happen to the row, but only the names in sheet Days, Eves and Mids will be "updated" based on sheet STAFFING DATA and the selected ComboBox value.
    disregarding whether there is any update to the names or not in sheet STAFFING DATA.
    For example if C.... in sheet STAFFING DATA:
    the current GROUP LEAD is Bardia Rajaei under Days column
    the current GROUP LEAD is Adam Newton under Eves column
    the current GROUP LEAD is Jason Stithem under Mids column

    Later on, in sheet STAFFING DATA it change to bla, bli and ble respectively.
    The need is only to update the name in sheet Days, Eves and Mids...
    So, in the userform, just select the "GROUP LEAD" value in ComboBox,
    and leave the TextBox empty, then click the UPDATE button,
    the sheet Days Group Lead name now is bla
    the sheet Eves Group Lead name now is bli
    the sheet Mids Group Lead name now is ble

    So that's my guess on what you want for the result.
    Karmapala,

    Your guess was exactly what I was attempting to do. I did notice that the PROCESS TECH (TR) position is doubled up on the Days, Eves and Mids Seniority sheets. It is only on the STAFFING DATA sheet once. I tried to delete the rows using the Userform and it didn't fix it and I also attempted to delete it directly, which caused "1"s to populate across the area modified. It is probably an easy fix, but I am not sure what needs to be done. Any help would be greatly appreciated!


    Thank you again,

    Adam

  7. #7
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Need some VBA ideas for inserting rows

    Quote Originally Posted by Newtonus_Prime View Post
    Karmapala,
    I did notice that the PROCESS TECH (TR) position is doubled up on the Days, Eves and Mids Seniority sheets.
    It is only on the STAFFING DATA sheet once.
    Very sorry as it's the result when I was coding it by trial and error,
    and then I forget to bring the sheet back to the original state.

    I tried to delete the rows using the Userform and it didn't fix it
    Yes, the code will not give you the expected result,
    or even maybe will throw you an error if the pre-condition state is not met.

    A state which not meet the pre-condition example :
    There are two 2 under PROCESS TECH (TR) in sheet STAFFING DATA, but
    There are 3 rows for PROCESS TECH (TR) on the other sheet (mids/days/eves).

    If the pre-condition is like above, then the code won't give the expected result.
    The pre-condition is as I mentioned it my reply #4.


    It is probably an easy fix, but I am not sure what needs to be done.
    Please have a look at the attachment.

    Please remember, to do the inserting/deleting row to all of that four sheets (staffing/mid/day/eve), the pre-condition must meet.
    So, remember not to insert/delete row manually to any of that four sheets ... OR...
    if you do it manually, please make sure that you also do it to the rest of the sheets.
    Attached Files Attached Files

+ 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. [SOLVED] SUMIF is Very Slow for 700 000 rows. SPEED UP Ideas?
    By tta.akmal in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-07-2019, 06:41 AM
  2. Inserting Rows Based On 8 Rows Per Mile in a Data Set
    By Mark123456789 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2017, 11:04 AM
  3. Replies: 1
    Last Post: 07-03-2015, 02:20 AM
  4. Replies: 0
    Last Post: 05-20-2014, 11:58 AM
  5. Inserting rows such that reference rows is after an automatic pagebreak
    By Tester80 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2013, 04:16 PM
  6. Need to plot pivottable but only certain rows/columns - ideas?
    By jackyoung2012 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 10-02-2013, 12:14 PM
  7. [SOLVED] Inserting multiple rows in excel with data in consecutive rows
    By technotronic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2005, 11:05 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