Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, need help with this code. For some reason will not run. What the code does right now, is take each name variable found in

Hello, need help with this code. For some reason will not run. What the code does right now, is take each name variable found in column F and creates a new worksheet for each name within the workbook.

However also in this code is a string that is supposed to make put each of the new worksheets in date order (Found in Column K) and then in numerical order (Found in column I), but the code keeps coming back with error.

Also, I am trying to figure out how to group some name variables in the column F. For example, if in Column F, the name variables it contains are (A,B,C,D). Right now the code separates and creates four new worksheets for each variable in Column F. But I want it to group A and B together, and leave C and D as their own new worksheets. The code I have so far is:

Sub company_statement() Dim lr As Long Dim ws As Worksheet Dim vcol, i As Integer Dim icol As Long Dim myarr As Variant Dim title As String Dim titlerow As Integer vcol = 6 Set ws = Sheets("Company Statement Hanley") lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row title = "A1:AE1" titlerow = ws.Range(title).Cells(1).Row icol = ws.Columns.Count ws.Cells(1, icol) = "Unique" For i = 2 To lr On Error Resume Next If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol) End If Next myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants)) ws.Columns(icol).Clear For i = 2 To UBound(myarr) ws.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 ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1") Sheets(myarr(i) & "").Columns.AutoFit Next ws.AutoFilterMode = False ws.Activate End If Next With Worksheets("HO NMX_AMO") .Cells.Sort Key1:=.Columns(11), Order1:=xlAscending, _ Key2:=.Columns(9), Order2:=xlAscending, _ Orientation:=xlTopToBottom, Header:=xlYes End Sub

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago