Splitting Data into Specific Worksheets

itsianusa

New Member
Joined
Jan 28, 2005
Messages
4
Hi all,

I'm trying to make a macro that will be able to split a worksheet into three by one columns information that has numbers 1-3 in them. I want all the rows that have a "1" in this specific column to go to one worksheet, all rows with a "2" to go into the next, etc...

Does anyone know how to populate these worksheets with a macro? I'm thinking a For/Next loop, but I have to admit that I'm quite rusty with even simple VB...

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You may be able to modify this to your needs?

Sub myFindXSh1to2()
'Run from standard module, like: Module1.
Dim c As Range, rng As Range, myCount
Dim Message, Title, Default, myFValue

'Get item to search for!
Message = "Find and move the rows," & vbCr & _
"that contain the string you enter below!" & vbCr & vbCr & _
"Only look in columns ""A"" through ""C.""" & vbCr & vbCr & _
"Search Sheet1, if found, move data" & vbCr & _
"to sheet2!" ' Set prompt.
Title = "Search Columns A through C!" ' Set title.
Default = "Test" ' Set default.
' Display message, title, and default value.
myFValue = InputBox(Message, Title, Default)

Application.ScreenUpdating = False
'Search range!
Set rng = Sheets("sheet1").Range("A2", Range("C65536").End(xlUp))
For Each c In rng
If c.Value = myFValue Then
myCount = myCount + 1
c.EntireRow.Copy Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0)
c.Rows.EntireRow.Delete
End If
Next c
Application.ScreenUpdating = True

MsgBox "Found and moved: " & myCount & ", rows of data!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,534
Messages
6,055,947
Members
444,839
Latest member
laurajames

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