I've got a macro which successfully takes a table with 44 columns and reduces it down to to 12. It splits the top section (where our supplier has sent no stock and the cell in the total column would show a 0) and sticks it at the top of the worksheet, and it inserts checkboxes (to an extent).
I tried really hard to make a markdown table but it wouldn't display properly. Below is (top) how the data currently looks and (bottom) the desired result! :-)
What I'm ideally wanting to do is make it so that the top section is formatted red (where we've not got any stock sent) and the checkboxes are filled down until the final row. I can't work out how to do this. I'd also like to sort the section NOT in red by column 'A' (code).
Any help most welcome!
Thanks
Sub separate()
Columns("A:N").Select
Range("N1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Delete Shift:=xlToLeft
Range("D5").Select
Range("F1").Select
ActiveCell.FormulaR1C1 = "CHK"
Columns("F:F").Select
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Columns("G:J").Select
Selection.Delete Shift:=xlToLeft
Columns("G:H").Select
Selection.Delete Shift:=xlToLeft
Columns("L:L").Select
Selection.Delete Shift:=xlToLeft
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Range("F5").Select
Columns("C:C").Select
Selection.Cut
Columns("E:E").Select
Selection.Insert Shift:=xlToRight
Columns("J:J").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("J1").Select
ActiveCell.FormulaR1C1 = "VAT"
Range("J6").Select
Dim wb As Workbook, ws As Worksheet, myrange As Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
Set range_i = Nothing
counter = 0
Tre = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For Tr = 2 To Tre
If ws.Cells(Tr, 13) = 0 Then
If Not myrange Is Nothing Then
Set myrange = Union(myrange, Range(ws.Cells(Tr, 1), ws.Cells(Tr, 13)))
Else
Set myrange = Range(ws.Cells(Tr, 1), ws.Cells(Tr, 13))
End If
counter = counter + 1
End If
If Not range_i Is Nothing Then
If ws.Cells(Tr, 13) > 0 Then
Set range_i = Union(range_i, Range(ws.Cells(Tr, 1), ws.Cells(Tr, 13)))
End If
Else
If ws.Cells(Tr, 13) > 0 Then
Set range_i = Range(ws.Cells(Tr, 1), ws.Cells(Tr, 13))
End If
End If
Next Tr
Sheets.Add.Name = "summary"
Set Tws = wb.Sheets("summary")
myrange.Copy
Tws.Range("A1").PasteSpecial
range_i.Copy
Tws.Range(Cells(1 + counter, 1), Cells(1 + counter, 13)).PasteSpecial
Sheets("Sheet1").Range("A1:M1").Copy
Sheets("summary").Select
Range("A1").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Application.DisplayAlerts = False
Sheets(Array("Sheet1")).Delete
Application.DisplayAlerts = True
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Range("D2").Select
ActiveCell.FormulaR1C1 = "o"
Columns("D:D").Select
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D268")
Range("D2:D268").Select
Range("E6").Select
End Sub