VBA Row Header

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
272
Office Version
  1. 365
Platform
  1. Windows
  2. 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?



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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Re: VBA Row Header Help!

Code:
TempSh.Range("A" & titlerow & ",A5").EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
 
Upvote 0
Re: VBA Row Header Help!

Hi Mart,

Excuse my ignorance as i have only been trying VBA for a few weeks.

can you advise where i need to replace your code into the code.
 
Upvote 0
Re: VBA Row Header Help!

Vba learner.

You have just been using Vba for a couple weeks and you wrote the code in Post #1
That shows your a very quick learner

You know what all this script is doing and now you want something more added. Is that what your saying?
 
Upvote 0
Re: VBA Row Header Help!

Hi My Aswer Is This

I managed to combine code from various forums to suit my needs by stepping into each of the code line to see whats happening and amending as required to suit what i am trying to achieve.

On this occasion I cant seem to write an amended code to add these rows in.

I guess that's the problem as i am using other peoples codes and combining additional lines of code & its turned into a nightmare when I am not skilled enough to write code from scratch.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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