Copy/Paste with no blank rows

craig2525

New Member
Joined
Oct 30, 2018
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Sheet 1 Sheet 2 Sheet 3 Sheet 4

excel1.PNG
excel2.PNG
excel3.PNG
excel4.PNG


How can I copy/paste the raw data from Sheet 1 to Sheets 2, 3 and 4? I am inputting the raw data into Sheet 1 and would like to automatically copy/paste into separate sheets according to the name in Sheet 1 column 1 (as shown)? I have no experience with VBA.
 
Here is a shorter method :

Code:
Sub ExtractToSheets()
    Dim ws     As Worksheet
    Dim wsNew  As Worksheet
    Dim rData  As Range
    Dim rfl    As Range
    Dim state  As String
    Set ws = ThisWorkbook.Sheets("Sheet1")
   
    With ws
        Set rData = .Range(.Cells(1, 1), .Cells(.Rows.Count, 11).End(xlUp))
        .Columns(.Columns.Count).Clear
        .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
       
        For Each rfl In .Range(.Cells(1, .Columns.Count), .Cells(.Rows.Count, .Columns.Count).End(xlUp))
            state = rfl.Text
           
            If WksExists(state) Then
               Sheets(state).Cells.Clear
            Else
               
                Set wsNew = Sheets.Add
                wsNew.Move After:=Worksheets(Worksheets.Count)
                wsNew.Name = state
            End If
           
            rData.AutoFilter Field:=6, Criteria1:=state
            rData.Copy Destination:=Worksheets(state).Cells(1, 1)
        Next rfl
    End With
    ws.Columns(Columns.Count).ClearContents
    rData.AutoFilter
End Sub
 
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You are welcome. I finally understood what you were looking for ... DUH ! Slap my forehead and call me dumb.

Cheers !!!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top