Consulting

Results 1 to 5 of 5

Thread: Sleeper: Inserting a Row under a Specified Value

  1. #1
    VBAX Newbie
    Joined
    Aug 2023
    Posts
    2
    Location

    Sleeper: Inserting a Row under a Specified Value

    Hello,

    Our company has an inventory list that we select items from for each job. Each item is assigned a "phase" (Travel, Commissioning, Installation, etc.) When it gets assigned a phase, I want to take the second and third column values in that row and have it populate on another sheet under the appropriate phase. So far I can only insert the row on the first unused row. Any help would be appreciated! Code and photos below:


    Sub CopyCatalogtoPickSheet()
    Dim PartIDField As Range
    Dim PartIDCell As Range
    Dim Rng As Range
    Dim WorkRng As Range
    Dim PSSheet As Worksheet
    Dim CSheet As Worksheet
    Set PSSheet = Worksheets("Material Pick Sheet")
    Set CSheet = Worksheets("Catalog")
    Set PartIDField = CSheet.Range("A6", CSheet.Range("A6").End(xlDown))
    For Each PartIDCell In PartIDField
    If PartIDCell.Value = "Module Installation" Then
    PartIDCell.Resize(1, 2).Offset(0, 1).Copy Destination:=PSSheet.Range("A1").Offset(PSSheet.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
    End If           
    Next PartIDCell
    PSSheet.Columns.AutoFit
    End Sub
    snip.jpg
    snip.jpg
    Last edited by Aussiebear; 08-15-2023 at 01:56 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    1. Welcome to the forum

    2. Please used CODE tags (that's the [#] icon) since it make the macro much easier to read

    3. Take a minute to read the FAQ in the link in my signature

    4. And finally, most times it's easier to understand an issue and offer suggestions and testing if you cn attach a small example workbook instead of screen shots, since otherwise people are just guessing
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Welcome to VBAX Jt13. If you wish to insert a blank row after every other row then the following should work

    Sub Insert_Row_After_Every_Other_Row()
    Dim rng As Range
    Dim CountRow As Integer
    Dim i As Integer
    Set rng = Selection
    CountRow = rng.EntireRow.Count
    For i = 1 To CountRow
       ActiveCell.EntireRow.Insert
       ActiveCell.Offset(2, 0).Select
    Next i
    End Sub
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Newbie
    Joined
    Aug 2023
    Posts
    2
    Location
    Hi Aussiebear,

    Thanks, but that's not quite what I was looking to do. In the first picture, the 3/4" panhead screw is tagged with "Module Installation". I would like to place it under the "Module Installation" row in the second picture, but I can only get it to insert in the next available row. Hope this clarifies things.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Okay, can you attach a sample workbook to enable us to test any coding please?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •