Consulting

Results 1 to 4 of 4

Thread: EntireRow.Copy Issues VBA

  1. #1
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    3
    Location

    Question EntireRow.Copy Issues VBA

    Thanks in advance for help, I am new to VBA and really appreciate it!

    I have created a workbook that I am hoping will help to organize my clinic's record requests. The plan is to be able to input information (under the "Input" sheet) and to then be able to direct the information to another sheet by making a selection in the "Provider" column (F) or the "Type of Record" Column (G).

    If "AG" is selected in column "F" in input sheet> entire row is copied to the "AG" Sheet
    If "DS" is selected in column "F" in input sheet> entire row is copied to the "DS" Sheet
    If "NL" is selected in column "F" in input sheet > entire row is copied to the "NL" Sheet
    If "EH" is selected in column "F" in input sheet> entire row is copied to the "EH" Sheet
    If "JH" is selected in column "F" in input sheet> entire row is copied to the "JH" Sheet
    If "RW" is selected in column "F" in input sheet> entire row is copied to the "RW" Sheet
    If "LS" is selected in column "F" in input sheet> entire row is copied to the "LS" Sheet
    If "SP" is selected in column "F" in input sheet> entire row is copied to the "SP" Sheet

    If "Clouded Images" is selected in column "G" in input sheet> entire row is copied to the "Rad Cloud" Sheet
    If "Faxed Record" is selected in column "G" in input sheet> entire row is copied to the "Faxed" Sheet


    I have entered some code that does not seem to work, please let me know what I am doing wrong!
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    3
    Location
    I'll be sure to remove my post. Any chance you can help me with my VBA code question?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Quote Originally Posted by qqtest View Post
    I'll be sure to remove my post. Any chance you can help me with my VBA code question?
    Or at least indicate here and there that you've asked in other forums

    Anyways …

    I think you vastly over complicated it.

    I doubt you really needed event handlers, although you could use them if written correctly

    1. This is written as a manually run sub

    2. Note that there is no check in the output records for duplicates, so you can append the same record from Input many times

    3. You could clear the AG..SP output sheets in the macro before running the copy part of the macro so that what ever is in Input as of macro run time would go to the output sheets cleanly



    Option Explicit
    Sub CopyRow()
        Dim rInput As Range, rRow As Range
        Dim F As String, G As String
        
        Set rInput = Worksheets("Input").Cells(1, 1).CurrentRegion
        
        For Each rRow In rInput.Rows
            With rRow
                .Cells(1, 6).Value = UCase(.Cells(1, 6).Value)      '   6 = col F
                .Cells(1, 7).Value = UCase(.Cells(1, 7).Value)      '   7 = col G
        
                F = .Cells(1, 6).Value
                G = .Cells(1, 7).Value
        
                Select Case F
                    Case "AG", "DS", "LS", "NL", "EH", "RW", "RF", "JH", "SP"
                        .Copy Sheets(F).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                
                        Select Case G
                            Case "CLOUDED IMAGES"
                                .Copy Sheets("Rad Cloud").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                            Case "FAXED RECORD"
                                .Copy Sheets("Faxed").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                        End Select
                
                End Select
            End With
        Next
    End Sub
    Attached Files Attached Files
    Last edited by Paul_Hossler; 10-04-2018 at 10:34 AM.
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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