Copy/Paste with no blank rows

craig2525

Board Regular
Joined
Oct 30, 2018
Messages
57
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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