473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need some help with a Group of Macro Needs

I'd like to create a Macro that will sort some raw data, apprx 20k lines,
remove some lines based upon a condition in a certain column. Then copy this
data into a new spreadsheet and sort the data again and delete the unwanted
data and repeat few more times in new sheets. End product will be
apprximately 7 or 8 sheets - 1 for Active Customers, Inactive Customers,
Pending Installs, Etc...

I'm getting hung up I believe with naming ranges. I can't seem to be able
to reuse my Ranges in differnt sheets. I've tried putting these ranges in a
new macro and point to a different sheet, but I'm probably missing something.

Below is my code:
Sub Install_Base()
Dim currentCell As Variant
With ActiveSheet

'Step 1 thru 6 of Install Base Job Doc
'-------------------------------------------------------------------------------

'Delete Columns AL-AZ
Columns("AL:AZ").Select
Selection.EntireColumn.Delete

'Delete Columns U-AH
Columns("U:AH").Select
Selection.EntireColumn.Delete

'Delete Columns D-J
Columns("D:J").Select
Selection.EntireColumn.Delete

'Move Column A to B
Columns("F:G").Cut
Columns("C:C").Insert Shift:=xlToRight

'Insert 3 columns between BU and Parent
Columns("H:J").Select
Selection.Insert Shift:=xlToRight

'Name Columns H thru J, "Count", "Region", and "Warranty" and Today's Date
Range("H2").Value = "Count"
Range("I2").Value = "Region"
Range("J2").Value = "Warranty"
Range("F1").Value = "Report Date:"
Range("G1") = Date
'Name Colums T - This column will be used to identify Systems Parts Only and
macro will
'delete non sytem part #'s
Range("T2").Value = "If Systems Part #s - Keep. Otherwise, delete"

'Name Colums U - This column will be used to Active or Pending Install
Range("U2").Value = "Active /Pending Install"

'Add a "1" to all the Rows in the Count columns
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Range("H3:H" & lastrow).Formula = "1"

'Add a Vlookup formula to determine Regions in Column I
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Range("I3:I" & lastrow).Formula = "=VLOOKUP(F3,Region!$A$2:$B$47,2,0)"

'Add a Formula to determine Warranty Status in Column J
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Range("J3:J" & lastrow).Formula = "=IF(P3>=$G$1,""Warranty"",""Expired"")"

'Add a Formula to determine whether a Systems Part # exist in Column T - 1
for exist, 0 for Non Systems items
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Range("T3:T" & lastrow).Formula =
"=IF(ISERROR(VLOOKUP(C3,Region!$I$2:$N$85,6,0))=TR UE,""Remove"",IF(VLOOKUP(C3,Region!$I$2:$N$85,6,0) =""Ignore"",""Remove"",""Keep""))"

'Add a Formula to Active or Pending Install
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Range("U3:U" & lastrow).Formula = "=IF(O3>0,""Active"",""Pending"")"
'Adjust Column Width to Autofit
Columns("A:S").Select
Selection.EntireColumn.AutoFit

'Highlight Columns C-D,H-J,L,Q-R with Blue Font
Range("C:D").Font.ColorIndex = 5
Range("H:J").Font.ColorIndex = 5
Range("L:L").Font.ColorIndex = 5
Range("Q:R").Font.ColorIndex = 5
'Set Workbook aligmnent to Left Indent
Worksheets("Edited").Range("A:S").HorizontalAlignm ent = xlLeft

'Sort the Data by Column T to increase the efficiency of the next Macro
Range("A2:T25000").Select
Selection.Sort Key1:=Range("T2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Delete Rows if Non Sytems items exist - value = 0, Column T of Edited sheet
Dim Rng As Range
Dim rngToDelete As Range
Dim rngToSearch As Range

Set rngToSearch = .Range(.Range("T2"), .Cells(Rows.Count, "T").End(xlUp))
.DisplayPageBreaks = False
For Each Rng In rngToSearch
If Rng.Value = "Remove" Then
If rngToDelete Is Nothing Then
Set rngToDelete = Rng
Else
Set rngToDelete = Union(Rng, rngToDelete)
End If
End If

Next Rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

'Sort the Data by Column T to increase the efficiency of the next Macro
Range("A2:T25000").Select
Selection.Sort Key1:=Range("O2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'Place cell in B1 once Macro finishes
Range("B1").Select

'Add a Formula to Active or Pending Install
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
If Cell.Value = "0" Then
..Range("T3:T" & lastrow).Formula = "=IF(O3>0,""Active"",""Pending"")"
End If

'-----------------------------------------------------------------------------------


'---------------------------------------------------------------------------------------
ActiveSheet.Copy After:=Worksheets("Edited")
Worksheets(4).Name = "Customer Active"

ActiveSheet.Copy After:=Worksheets("Customer Active")
Worksheets(5).Name = "Internal Active"

ActiveSheet.Copy After:=Worksheets("Internal Active")
Worksheets(6).Name = "Pending Install"

ActiveSheet.Copy After:=Worksheets("Pending Install")
Worksheets(7).Name = "All Inactive"

ActiveSheet.Copy After:=Worksheets("All Inactive")
Worksheets(8).Name = "FS"

ActiveSheet.Copy After:=Worksheets("FS")
Worksheets(9).Name = "AL"

ActiveSheet.Copy After:=Worksheets("AL")
Worksheets(10).Name = "Scanners"

End With
End Sub
Sub Edit_Customer() 'Edit Customer Active Sheet
Dim currentCell As Variant
Sheets("Customer Active").Activate

With ActiveSheet

'Delete Rows if Non Sytems items exist - value = 0, Column T of Edited sheet
Dim Rng As Range
Dim rngToDelete As Range
Dim rngToSearch As Range

Set rngToSearch = .Range(.Range("U2"), .Cells(Rows.Count, "U").End(xlUp))
.DisplayPageBreaks = False
For Each Rng In rngToSearch
If Rng.Value = "Pending" Then
If rngToDelete Is Nothing Then
Set rngToDelete = Rng
Else
Set rngToDelete = Union(Rng, rngToDelete)
End If
End If

Next Rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

End With

'Sort the Customer Active sheet by Column U, Pending Install Yes or No
' With ActiveSheet
' Range("A2:T25000").Select
' Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlYes, _
' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
' DataOption1:=xlSortNormal

'Place cell in B1 once Macro finishes
'Range("B1").Select
'End With

End Sub

Sub Internal_Active() 'Macro to edit the Internal Active sheet
Sheets("Internal Active").Activate

With ActiveSheet
Dim EndData As Long
Application.ScreenUpdating = False

EndData = Cells(Rows.Count, 1).End(xlUp).Row

With Range(Cells(2, 1), Cells(EndData, 2))
.Sort Key1:=Range("C2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With

Application.ScreenUpdating = True
End With

End Sub

Sub Pending_Install() 'Macro to edit the Pending Install sheet
Sheets("Internal Active").Activate

With ActiveSheet
Dim EndData As Long
Application.ScreenUpdating = False

EndData = Cells(Rows.Count, 1).End(xlUp).Row

With Range(Cells(2, 1), Cells(EndData, 2))
.Sort Key1:=Range("C2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With

Application.ScreenUpdating = True
End With

End Sub

Sub All_Inactive() 'Macro to edit the All Inactive sheet
End Sub

Sub All_FS() 'Macro to edit the FS sheet
End Sub

Sub Scanners() 'Macro to edit the Scanners sheet
End Sub

Private Sub CommandButton2_Click() 'This Macro will run all of the above
Macros
Call Install_Base
Call Edit_Customer
'Call Internal_Active
'Call Pending_Install
End Sub
May 25 '07 #1
0 2019

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
6
by: Dos Lil | last post by:
I have a comobox in the main form which has a query attached to it to list the employee numbers.I have written this code to requry the control in the control's after update event Private Sub...
7
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One...
11
by: jlara | last post by:
Working on an embedded controller, I generally find it convenient to define the following de-referenced pointer: #define portb (*(unsigned char *)(0x03u)) This enable me to write to a port as...
14
by: Malcolm | last post by:
Hi, I have the following which fails with "disagreement in number of macro arguments" when compiling with Imagecraft ICCAVR. Has anyone got any ideas - its not vital but would make the code a...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
1
by: omni77 | last post by:
I am such a beginner that I can only do the 'record' macros, but I have promised to help someone and I find that I'm not able. Would you please write a macro for me since I have run out of time and...
30
imrosie
by: imrosie | last post by:
Hello, I took over an application with forms, macros, reports....I've changed some of the controls on the forms,but left the names of forms in tack. I keep getting an error stating that the macro...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.