0

I have a list of accounts with names in column G. Sometimes the account has two names (column H) or three names (column I) and I'd like the account to appear the same but with the name of the person in column H at the bottom of the list.

I currently can copy the entire row, but I want the information from column A:F and then the name in column H to appear in column G at the bottom of my list depending on if there's text in column H.

Public Sub CopyRows()
    Sheets("Exposure Distribution").Select
    ' Find the last row of data
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    ' Loop through each row
    For x = 2 To FinalRow
        ' Decide if to copy based on column H
        ThisValue = Cells(x, 8).Value
        If Application.WorksheetFunction.IsText(ThisValue) = "True" Then
            Cells(x, 1).Resize(1, 10).Copy
            Sheets("Exposure Distribution").Select
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Cells(NextRow, 1).Select
            ActiveSheet.Paste
            Sheets("Exposure Distribution").Select
        End If
    ThisValue = Cells(x, 9).Value
        If Application.WorksheetFunction.IsText(ThisValue) = "True" Then
            Cells(x, 1).Resize(1, 10).Copy
            Sheets("Exposure Distribution").Select
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Cells(NextRow, 1).Select
            ActiveSheet.Paste
            Sheets("Exposure Distribution").Select
        End If
      ThisValue = Cells(x, 10).Value
        If Application.WorksheetFunction.IsText(ThisValue) = "True" Then
            Cells(x, 1).Resize(1, 10).Copy
            Sheets("Exposure Distribution").Select
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Cells(NextRow, 1).Select
            ActiveSheet.Paste
            Sheets("Exposure Distribution").Select
        End If
    Next x
End Sub

I want the original row information in A:F to remain the same depending on the row and the name from column G to be replaced with the name in column H at the bottom of the data set depending on if there's text.

cybernetic.nomad
  • 6,100
  • 3
  • 18
  • 31
chaneque5
  • 19
  • 4
  • 1
    You really want to [avoid using select](https://stackoverflow.com/questions/40019981/how-to-avoid-using-select-activate-activesheet-activecell-in-my-specific-vba) in your code – cybernetic.nomad Jul 23 '19 at 16:38
  • It is not clear what you are trying to accomplish, All your code does is makes duplicates of the same row and paste the 3 duplicates below your current data. What are you trying to accomplish. e.g. 1st duplicate do nothing; 2nd duplicate delete the cell in column G, to shift the second name to the left; 3rd duplicate delete the cells in columns G and H, to shift the third name to the left. This will give you one duplicate and 2 new entries. Is this what you are trying to accomplish? If not please clarify and/or provide and decent example of your start and end product. – GMalc Jul 23 '19 at 21:07
  • This is exactly what I'm trying to accomplish ^^ – chaneque5 Jul 24 '19 at 14:57

0 Answers0