Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2004, 01:48 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Processing text file from Oracle in Excel

Hi,

I work as a Financial Analyst for a MNC using Oracle.
Financial data from Oracle are save to text before importing
into Excel spreadsheet for reprocessing.

The monthly volume of work on this activity are taking away the
bulk of my time, leaving me little time for analysis.

As i am relatively new to VBA, i am coding as i learn on the job.
I have automate much of the process to cut down on a few days
of work .

i have writing several macros to align the header field.

Q1)Next area of improve, is to to add in additional column and append new information in certain key cell on to the colums before a detail level of SORTING & DELETION of unused rows.

Can i refer to any VBA function that will do a good job on this.
Is there any good example on SORTING in VBA.

Q2) Once this is done, i will need reused this complete set of MACROS and apply to a dozen or more identical files.

Can i request for help to automate this process, whereby excel will
automatically apply the complete set of macro onto a DIRECTORY folder
with irregular filename ?

i read about DIR function earlier in some topics but it can be confusing. Any Macros example will be extremely helpful.

Understand that it's a lot of work,pls don't assume that i'm asking for instant solution but rather i just need help to point me to the
correct direction.

Appreciate all the kind advice to help me advice further.

Thanks & Regards

 
Old October 18th, 2004, 02:48 AM
Authorized User
 
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My job for the last 15 years has been data retrieval & analysis in support of the Finance Department of a large company. As a principle I strongly suggest that you put all your data into a single table wherever possible - using MS Access if the number of records is likely to exceed the 65,536 Excel limit. The more powerful data handling capabilities of Excel such as Pivot Tales and Filters can then be used for analysis.

I also suggest that you do *not* put all your macros into a single routine, especially when importing text files. Files are likely to be corrupted at any time, and it is sometimes difficult to see where the problem lies. A more modular approach helps with this - as well as making it unnecessary to re-run the full routine when problem occur.

An alternative is to devide the code with message boxes of the sort :-
Code:
rsp = MsgBox("Do you wish to import the text file ?", vbYesNoCancel)
If rsp = vbCancel Then End
If rsp = vbYes Then ................
The code below consolidates data from all files in a folder :-
Code:
'===============================================
'- Generic code for processing all
'- workbooks contained in a folder.
'- workbooks must be the only ones in the folder.
'- Change "Sub Transfer_data()" etc. as required.
'------------------------------------------------
'- in this example to summarise tables in all
'- worksheets in all workbooks :-
'- worksheets must be contain tables which are
'- identical to the master, with headings in row 1.
'- master sheet is remade each time.
'- run this code from the master book
'- by Brian Baulsom (BrianB) January 1st.2004
'----------------------------------------------
Dim ToBook As String
Dim ToSheet As Worksheet
Dim NumColumns As Integer
Dim ToRow As Long
Dim FromBook As String
Dim FromSheet As Worksheet
Dim FromRow As Long
Dim LastRow As Long
'-
'--------------------------
Sub FILES_FROM_FOLDER()
'--------------------------
    Application.Calculation = xlCalculationManual
    ChDrive ActiveWorkbook.Path
    ChDir ActiveWorkbook.Path
    ToBook = ActiveWorkbook.Name
    '---------------------------
    '- MASTER SHEET
    '---------------------------
    Set ToSheet = ActiveWorkbook.Worksheets(1)
    NumColumns = ToSheet.Range("A1").End(xlToRight).Column
    ToRow = ToSheet.Range("A65536").End(xlUp).Row
    '- clear master
    If ToRow <> 1 Then
        ToSheet.Range(Cells(2, 1), Cells(ToRow, NumColumns)).ClearContents
    End If
    ToRow = 2
    '------------------------------
    '- main loop to open each file
    '------------------------------
    FromBook = Dir("*.xls")
    While FromBook <> ""
        If FromBook <> ToBook Then
            Application.StatusBar = FromBook
            Transfer_data
        End If
        FromBook = Dir
    Wend
    '-- close
    MsgBox ("Done.")
    Application.StatusBar = False
    Application.Calculation = xlCalculationAutomatic
End Sub
'---------------------------------------------------------------
'- CHANGE THIS CODE TO DO WHAT YOU WANT TO THE OPENED WORKBOOK
'----------------------------------------------------------------
Sub Transfer_data()
    Workbooks.Open FileName:=FromBook
    For Each FromSheet In Workbooks(FromBook).Worksheets
        LastRow = FromSheet.Range("A65536").End(xlUp).Row
        '------------------------------
        '- copy paste to master sheet
        FromSheet.Range(Cells(2, 1), Cells(LastRow, NumColumns)).Copy _
            Destination:=ToSheet.Range("A" & ToRow)
        '------------------------------
        '- set next ToRow
        ToRow = ToSheet.Range("A65536").End(xlUp).Row + 1
    Next
    Workbooks(FromBook).Close savechanges:=False
End Sub
'==== EOP ======================================
-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
 
Old November 23rd, 2005, 03:53 PM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am a new VBA programmer. This code helped me a lot because I have around 5000 excel files I needed them to be in one file which worked fine with this code thx :)

Now.
I also need to copy one cell from the each file and past it to a specific cell in the master list.
This operation need to be implemented to the original code we have here.

Any help :)
Thank you







Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Excel file into a text file zone Excel VBA 3 July 26th, 2007 02:09 PM
Import from Excel sheet to a text file zone Excel VBA 1 July 26th, 2007 10:34 AM
importing text file into excel stealthdevil Excel VBA 2 July 10th, 2007 11:28 AM
Importing text file into excel anamarijaf Excel VBA 4 January 27th, 2007 05:50 AM
Text file importing & data processing jarpola Excel VBA 0 January 16th, 2007 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.