Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined one which creates a pivot table and sorts it into different fromats. Here is the code, can any body help? - Sub Update_Land_Actuals()
-
On Error Resume Next
-
If InputBox("Enter password to continue", "Centex Homes") <> "***" Then Exit Sub
-
Sheets("Detail").Visible = True
-
Application.DisplayAlerts = False
-
Sheets("Actuals").Delete
-
Application.DisplayAlerts = True
-
Sheets("Detail").Select
-
Sheets("Detail").Cells.ClearContents
-
Call GetRetrievedData
-
Call CombineData
-
Call FormatTotalsSheet
-
Application.ScreenUpdating = True
-
MsgBox "Land Actuals updated", vbOKOnly + vbInformation, "Centex Homes"
-
End Sub
-
-
-
Private Sub GetRetrievedData()
-
On Error Resume Next
-
Dim i As Integer, CompositeBook As String
-
CompositeBook = ThisWorkbook.Name
-
Const DownloadFile As String = "ActualsDownload"
-
-
Application.ScreenUpdating = False
-
Application.ShowWindowsInTaskbar = False
-
For i = 1 To 3
-
Workbooks.Open Filename:=DownloadPath & DownloadFile & i & ".xls"
-
ActiveSheet.Copy Before:=Workbooks(CompositeBook).Sheets(1)
-
ActiveSheet.Move After:=Sheets(Sheets.Count)
-
Windows(DownloadFile & i & ".xls").Close (False)
-
Next i
-
Application.ShowWindowsInTaskbar = True
-
Sheets("Detail").Select
-
End Sub
-
-
-
Private Sub CombineData()
-
Dim i As Integer
-
Const DownloadFile As String = "ActualsDownload"
-
Application.ScreenUpdating = False
-
Sheets("Detail").Select
-
Cells.Clear
-
For i = 1 To 3
-
Sheets(DownloadFile & i).Select
-
Range(Range("A2"), Range("A2").End(xlToRight)).Select
-
Range(Selection, Selection.End(xlDown)).Select
-
Selection.Copy
-
Sheets("Detail").Select
-
Selection.End(xlDown).Select
-
Range("A65000").End(xlUp).Offset(1, 0).Select
-
ActiveSheet.Paste
-
Application.CutCopyMode = False
-
Next i
-
Application.DisplayAlerts = False
-
For i = 1 To 3
-
Sheets(DownloadFile & i).Select
-
ActiveWindow.SelectedSheets.Delete
-
Next
-
Cells.EntireColumn.AutoFit
-
Application.DisplayAlerts = True
-
End Sub
-
-
-
Private Sub FormatTotalsSheet()
-
On Error Resume Next
-
Dim cell As Range
-
Application.ScreenUpdating = False
-
Cells.Font.Size = 8
-
For Each cell In Range(Range("A2"), Range("A2").End(xlDown))
-
cell = cell & "LD" & cell.Offset(0, 1)
-
Next
-
For Each cell In Range(Range("G2:H2"), Range("G2:H2").End(xlDown))
-
cell = cell.Value
-
Next
-
Columns("B:B").Delete Shift:=xlToLeft
-
Range("A1") = "JOB"
-
Range("B1") = "CC"
-
Range("C1") = "DESCRIPTION"
-
Range("D1") = "VENDOR"
-
Range("E1") = "REFERENCE"
-
Range("F1") = "AMOUNT"
-
Range("G1") = "DATE"
-
Columns("F:F").Style = "Comma"
-
Rows("1:1").Font.Bold = True
-
Rows("1:1").HorizontalAlignment = xlCenter
-
Cells.EntireColumn.AutoFit
-
Columns("G:G").NumberFormat = "mm/dd/yy"
-
Range("A1").CurrentRegion.Select
-
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
-
, Order2:=xlAscending, Key3:=Range("G2"), Order3:=xlAscending, Header:= _
-
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
-
Range("A2").Select
-
ActiveWindow.FreezePanes = True
-
End Sub
-
-
-
Sub Create_Actuals_Pivot()
-
'****** DYNAMIC PIVOT TABLE********
-
On Error Resume Next
-
If InputBox("Enter password to continue", "Centex Homes") <> "***" Then Exit Sub
-
Application.ScreenUpdating = False
-
Application.DisplayAlerts = False
-
Sheets("Detail").Visible = True
-
Sheets("Detail").Select
-
Sheets("Actuals").Delete
-
Application.DisplayAlerts = True
-
-
'****** DYNAMIC PIVOT TABLE START********
-
Sheets("Detail").Select
-
ActiveSheet.Range("A1").Select
-
Dim DataSource As Range, i As Integer, cell As Range
-
Set DataSource = Range("A1").CurrentRegion
-
Application.ScreenUpdating = False
-
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
-
DataSource, TableDestination:="", TableName:="CCPivotTable"
-
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
-
-
ActiveSheet.Cells(3, 1).Select
-
ActiveSheet.PivotTables("CCPivotTable").SmallGrid = False
-
ActiveSheet.PivotTables("CCPivotTable").AddFields RowFields:="CC", PageFields _
-
:="JOB"
-
-
With ActiveSheet.PivotTables("CCPivotTable").PivotFields("AMOUNT")
-
.Orientation = xlDataField
-
.Caption = "Cost Code Totals"
-
.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
-
End With
-
-
Application.CommandBars("PivotTable").Visible = False
-
'****** DYNAMIC PIVOT TABLE END********
-
ActiveSheet.Name = "Actuals"
-
-
For Each cell In Range(Range("B5"), Range("B5").End(xlDown))
-
cell.Offset(0, 1).FormulaR1C1 = "=IF(ISNA(VLOOKUP(RC[-2],CostCodes!R2C1:R40000C3,2,FALSE)),"""", VLOOKUP(RC[-2],CostCodes!R2C1:R40000C3,2,FALSE))"
-
Next
-
-
Cells.Font.Size = 8
-
Cells.EntireColumn.AutoFit
-
Range("C4") = "Description"
-
Rows("4:4").Font.Bold = True
-
Rows("4:4").HorizontalAlignment = xlCenter
-
Range("B1").Select
-
Range("B1").Font.Size = 11
-
Range("B1").Font.Bold = 11
-
Range("C1").FormulaR1C1 = "=IF(ISNA(VLOOKUP(RC[-1],LandJobs!R[1]C[-2]:R[300]C[1],4,FALSE)),"""", VLOOKUP(RC[-1],LandJobs!R[1]C[-2]:R[300]C[1],4,FALSE))"
-
Range("C1").InsertIndent 1
-
Range("C1").Font.Size = 11
-
Range("C1").Font.Bold = True
-
Range("C1:E1").Merge True
-
ActiveSheet.ScrollArea = "A1:B200"
-
ActiveSheet.PivotTables("CCPivotTable").EnableDrilldown = False
-
Sheets("Detail").Visible = False
-
Call ShowDetailButton
-
Application.ScreenUpdating = True
-
End Sub
-
-
-
Private Sub Detail()
-
On Error GoTo Err_DetailHandler
-
Dim CostCode As String
-
CostCode = Range("A" & ActiveCell.Row).Value
-
Application.ScreenUpdating = False
-
If WorksheetFunction.Sum(ActiveCell.EntireRow) = 0 Then Exit Sub
-
If Range("A" & ActiveCell.Row).Value > 70000 And Range("A" & ActiveCell.Row).Value < 79999 = False Then Exit Sub
-
ActiveSheet.PivotTables("CCPivotTable").EnableDrilldown = True
-
ActiveCell.ShowDetail = True
-
ActiveSheet.Name = "Detail for C.C. " & CostCode
-
Cells.Font.Size = 8
-
Columns("F:F").Style = "Comma"
-
Range("A1").Select
-
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _
-
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
-
Range("A2").Select
-
ActiveWindow.FreezePanes = True
-
Columns("G:G").NumberFormat = "mm/dd/yy"
-
Range("F10000").End(xlUp).Offset(1, 0).Select
-
ActiveCell = "=SUM(" & ActiveCell.Offset(-1, 0).End(xlUp).Address & ":" & ActiveCell.Offset(-1, 0).Address & ")"
-
ActiveCell.Font.Bold = True
-
Cells.EntireColumn.AutoFit
-
ActiveSheet.Buttons.Add(535, 16.5, 126.75, 18).Select
-
Selection.OnAction = "HideDetail"
-
Selection.Characters.Text = "Hide Detail"
-
With Selection.Characters(Start:=1, Length:=11).Font
-
.FontStyle = "Bold"
-
.Size = 8
-
End With
-
-
Range("A2").Select
-
-
Exit Sub
-
-
Err_DetailHandler:
-
If Err.Number = 1004 Then
-
Range("B" & ActiveCell.Row).Select
-
Resume
-
Else
-
Exit Sub
-
End If
-
End Sub
-
-
-
Private Sub HideDetail()
-
Application.DisplayAlerts = False
-
If Left(ActiveSheet.Name, 10) = "Detail for" Then ActiveWindow.SelectedSheets.Delete
-
Sheets("Actuals").Select
-
-
ActiveSheet.PivotTables("CCPivotTable").EnableDrilldown = False
-
Application.DisplayAlerts = True
-
End Sub
-
-
-
Private Sub ShowDetailButton()
-
Rows("2:2").RowHeight = 26.25
-
ActiveSheet.Buttons.Add(141.75, 20.25, 129, 16.5).Select
-
Selection.OnAction = "Detail"
-
Selection.Characters.Text = "Show Cost Code Detail"
-
With Selection.Characters(Start:=1, Length:=21).Font
-
.FontStyle = "Bold"
-
.Size = 8
-
End With
-
Range("a5").Select
-
ActiveWindow.FreezePanes = True
-
End Sub
0 3469 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sunilkeswani |
last post by:
I need help with exporting data from 2 access tables, into 2 existing
spreadsheets in a single Excel file.
Currently, I am using this code:
DoCmd.TransferSpreadsheet acExport, 8, "Table1", "D:\Test.xls", True
|
by: Nick M |
last post by:
Hello All,
Excellent info here Thanks!
I am very new to using access in general and I am on a learning curve.
I'm trying to import an excel workbook (with worksheets) into an access db
via a macro. (I'll get to using VB later on).
What I would like to do is import a single workbook w/three seperate
worksheets into three seperate access tables AND truncate the time stamp
that is used in the excell sheet via a macro.
|
by: Niklas |
last post by:
Hi
Before I start coding I need to be sure that nobody else has not done it yet
and that I can use it.
I need an import utility which import data from Excel to a database or some
object in .NET. The data in Excel is not in structured columns but can exist
everywhere in the workbook. For example if I am supposed to import a person
and all his/her cars which exist in a workbook I want to be able to create an
import protocol and specify...
|
by: e.h.doxtator |
last post by:
All
I'm a Python newbie, and I'm just getting to the wonders of COM
programming. I am trying to programmatically do the following:
1. Activate Excel
2. Add a Workbook
3. Add a Worksheet
4. Populate the new Worksheet
5. Repeat steps 3,4 while there is data.
|
by: Senthil |
last post by:
Hi All
I need to create an Excel report and create a command button and
have to run a macro on the
click event that will print all the pages in the Excel workbook.
I am able to create the report from the database but I am not sure how
do I put a command button and associate a macro with that using C#. Can
anyone help me??
Thanks in advance.
Senthil
| |
by: NeverLift |
last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers.
I have a VBA-coded macro in an Excel workbook that is to open another existing workbook -- a .xls file, not .csv -- copy data from it, paste that into the original workbook where the macro resides, then close the source workbook.
If I use the debugger to step through the macro -- putting a breakpoint at its first executable line, run...
|
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= |
last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes
the sheet. Im noticing that the Excel process is still running after I have
closed and disposed of my excel objects.
The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the Excel
process remains after exiting the sub (and until I exit the application)
Sub Test1
Dim...
|
by: Gary Dunne |
last post by:
Hi All,
I'm struggling to find the correct syntax for creating a Pivot table in
an excel file via VB . Net 2005
The Excel help file is not particularly helpful where parameters are
concerned (It rarely mentiones the required data types etc)
The following is as far as I can get;
Dim excelApp As Excel.Application
|
by: blazedaces |
last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found (correct me if I'm wrong about this) that can write excel 2007 files. The program works. I've tested it out on very small files (I will include the commented out main method that you can use to test this out yourself if you'd like, that is assuming you...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |