Potential Macro Question

hellokirsten

New Member
Joined
Jan 11, 2018
Messages
17
Hi all! Very happy to find this resource
I will try to be as thorough/concise as I can be

- I have a CSV file that we download for a number of customers. I have created a macro to remove all of the unnecessary information from that CSV file
- Now, there is a field of audit notes that I am trying to divide into these different sections: Idle (notes that contain "idle"), Hardware (notes that contain "battery, heartbeat, transition, and transport"), and Install (notes that contain "initial" or "engine")
- For those three different sections, I am wanting to build something that will take that full file, and divide it into three different sheets

I've tried to record a macro - but the line items range from 20 - 700, so the recording of the macro did not work very well.
Any help would be greatly appreciated!
 
In that case try
Code:
Sub FilterToNewSheets()

   Dim SrcWs As Worksheet
   Dim CritAry As Variant
   Dim ShtAry As Variant
   Dim Usdrws As Long
   Dim Cnt As Long
   
   CritAry = Array("*idle*", "*battery*", "*heartbeat*", "*transition*", "*transport*", "*initial*", "*engine*")
   ShtAry = Array("Idle", "Hardware", "Hardware", "Hardware", "Hardware", "Install", "Install")
   Set SrcWs = ActiveSheet
   
   With SrcWs
      Usdrws = .Range("A" & Rows.Count).End(xlUp).Row
      .Columns(6).Copy .Columns(7)
   
      If .AutoFilterMode Then .AutoFilterMode = False
      For Cnt = LBound(CritAry) To UBound(CritAry)
         If Not shtexists(CStr(ShtAry(Cnt))) Then Sheets.Add(, Sheets(Sheets.Count)).Name = ShtAry(Cnt)
         .Range("A1:G" & Usdrws).AutoFilter Field:=6, Criteria1:=CritAry(Cnt)
         On Error Resume Next
         .Range("A2:F" & Usdrws).SpecialCells(xlVisible).Copy Sheets(ShtAry(Cnt)).Range("A" & Rows.Count).End(xlUp).Offset(1)
         .Range("G2:G" & Usdrws).SpecialCells(xlVisible).ClearContents
         On Error GoTo 0
      Next Cnt
      .AutoFilterMode = False
      .Columns(7).Clear
   End With
End Sub

Public Function shtexists(ShtName As String) As Boolean
    On Error Resume Next
    shtexists = (LCase(Sheets(ShtName).Name) = LCase(ShtName))
    On Error GoTo 0
End Function
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You are a miracle worker.
is there something I can add in to bring over the labels from sheet 1 over to the next 3?
thank you so so so much!
 
Upvote 0
Change this as shown in red
Code:
.Range("[COLOR=#ff0000]A1[/COLOR]:F" & Usdrws).SpecialCells(xlVisible).Copy Sheets(ShtAry(Cnt)).Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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