Find Value in Cell, Copy Row to New Sheet, Using 3 different Variables

Vanish29

New Member
Joined
Apr 28, 2016
Messages
26
I am having difficulty creating this Macro:
Purpose: Using a report that is generated each month, pull information from main sheet and copy onto new sheet, format the sheet and sum relevant numbers.
Complete Process:
1) Create 3 new sheet with static names, and copy header information to each sheet. (Sheet X, Y & Z)
2) Search Column D to find 13, then copy that entire row and paste onto Sheet X, after the header information
3) Search Column B to find Value Y, then copy that entire row and paste onto Sheet Y, after header information. Repeat until all Value Y has been copied.
4) Search Column B to find Value Z, then copy that entire row and paste onto Sheet Z, after header information. Repeat until all Value Z has been copied
5) Select Sheet X. Delete Columns F, G, H, J, K, L, N, O. Select G2, give double-lined Bottom Border. Then sum G in next empty cell.
6) Select Sheet Y. Delete Columns F, G, H, J, K, L, N, O. Select G9, give double-lined Bottom Border. Then sum G in next empty cell.
7) Select Sheet Z. Delete Columns G, H, I, J, K, L, M, O. Select G10, give double-lined Bottom Border. Then sum G in next empty cell.

Please note that X, Y & Z values are static and will not change.
I really only need assistance with steps 2 - 4, but I have found that if you know the end goal, then it is easier to solve the issue.

Here is some of my code for the other steps
Code:
   Sheets.Add After:=ActiveSheet
    Sheets("Sheet2").Select
    Sheets("Sheet2").Name = "X"
    Sheets.Add After:=ActiveSheet
    Sheets("Sheet3").Select
    Sheets("Sheet3").Name = "Y"
    Sheets.Add After:=ActiveSheet
    Sheets("Sheet4").Select
    Sheets("Sheet4").Name = "Z"




Rows("2:2").Select
    Selection.Copy
    Sheets("X").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    With Selection
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlLTR
        .MergeCells = False
    End With
    Cells.Select
    Cells.EntireColumn.AutoFit
Sheets("Y").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    With Selection
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlLTR
        .MergeCells = False
    End With
    Cells.Select
    Cells.EntireColumn.AutoFit
Sheets("Z").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    With Selection
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlLTR
        .MergeCells = False
    End With
    Cells.Select
    Cells.EntireColumn.AutoFit
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
How about
Code:
Sub CopyToShts()
   Dim Ws As Worksheet
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("X", 4, 13, "Y", 2, "Y", "Z", 2, "Z")
   Set Ws = ActiveSheet
   For i = 0 To UBound(Ary) Step 3
      Sheets.Add(, Sheets(1)).Name = Ary(i)
      If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
      Ws.Range("A2").AutoFilter Ary(i + 1), Ary(i + 2)
      Ws.AutoFilter.Range.Copy Sheets(Ary(i)).Range("A2")
   Next i
End Sub
for steps 1 to 4
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
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