VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Good morning my peers,
I was wondering if anyone could help with the below code.
My row header is from row is from "A1:L1"
however i need to have A:1 toL1 & subsequent rows to "A5 to L5" copied into the new tabs.
can anyone help amend this beast?
I was wondering if anyone could help with the below code.
My row header is from row is from "A1:L1"
however i need to have A:1 toL1 & subsequent rows to "A5 to L5" copied into the new tabs.
can anyone help amend this beast?
Code:
Sub MoveOnCondition()
Dim DataSh As Worksheet, xWs As Worksheet, TempSh As Worksheet
Dim w As Integer
Dim MySheetName As String
Dim Shp As Shape
Dim LR As Long, FinalRow As Long
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
With Application
.ScreenUpdating = False
.DisplayStatusBar = True
.StatusBar = "!!! Please Be Patient...Updating Records !!!"
.EnableEvents = False
.Calculation = xlManual
End With
'Delete Existing Sheets Except Sheet1
Set DataSh = Worksheets("Sheet1")
Application.DisplayAlerts = False
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> DataSh.Name Then
xWs.Delete
End If
Next
Application.DisplayAlerts = True
'Create Temp Sheet
w = ThisWorkbook.Worksheets.Count
MySheetName = "Temp"
DataSh.Copy After:=Worksheets(w)
ActiveSheet.Name = MySheetName
'Delete Shapes
Set TempSh = ActiveSheet
For Each Shp In TempSh.Shapes
If Shp.Type <> msoPicture Then
Shp.Delete
End If
Next Shp
'Delete Filtered Range
LR = TempSh.Range("A" & Rows.Count).End(xlUp).Row
For f = LR To 1 Step -1
If TempSh.Cells(f, 6) = "" Or TempSh.Cells(f, 6) < 0.2 Then
TempSh.Rows(f).Delete
End If
Next
'Parse Data
vcol = 4
FinalRow = TempSh.Cells(TempSh.Rows.Count, vcol).End(xlUp).Row
title = "A1:L1"
titlerow = TempSh.Range(title).Cells(1).Row
icol = TempSh.Columns.Count
TempSh.Cells(1, icol) = "Unique"
For i = 2 To FinalRow
On Error Resume Next
If TempSh.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(TempSh.Cells(i, vcol), TempSh.Columns(icol), 0) = 0 Then
TempSh.Cells(TempSh.Rows.Count, icol).End(xlUp).Offset(1) = TempSh.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(TempSh.Columns(icol).SpecialCells(xlCellTypeConstants))
TempSh.Columns(icol).Clear
For i = 2 To UBound(myarr)
TempSh.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move After:=Worksheets(Worksheets.Count)
End If
TempSh.Range("A" & titlerow & ":A" & FinalRow).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
Sheets(myarr(i) & "").Columns("AA:AA").Delete
Sheets(myarr(i) & "").Columns.AutoFit
With Sheets(myarr(i) & "").Columns("B:G").Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With ActiveWindow
If .FreezePanes Then .FreezePanes = False
.SplitColumn = 0
.SplitRow = 1
.FreezePanes = True
End With
Next
Application.DisplayAlerts = False
TempSh.Delete
Application.DisplayAlerts = True
With Application
.ScreenUpdating = True
.DisplayStatusBar = True
.StatusBar = False
.EnableEvents = True
.Calculation = xlAutomatic
End With
End Sub