+ Reply to Thread
Results 1 to 3 of 3

MS Excel - VBA (Macros)

  1. #1
    Registered User
    Join Date
    04-23-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    1

    MS Excel - VBA (Macros)

    I am having problems with the macros I set-up in my spreadsheet. It's not working the way I wanted it to work.

    Here's the scenario: I have several excel spreadsheets extracted from my Software and these consists of 8 entities which I wanted to consolidate in one excel file. All sheets, including the consolidated spreadsheet (master file) have the same reference cells.

    What I wanted to happen is to lessen the time for consolidation. I wanted to have the files I extracted from the software to go directly to its specified folder, all the while at the same time, populating my master spreadsheet of the date from extracted files. The figures should be consolidated in column B. It's actually two columns master files - 1st column for the description and the 2nd column for the amount.

    Below is the macro I set:


    Option Explicit

    Sub ImportConsolidateData()

    ' Consolidate Macro
    ' Import the first sheet from files in a folder
    'WCC Database\per entity
    Dim strFileName As String, sName As String
    Dim MstWb As Workbook, StrWb As Workbook
    Dim NR As Long, LR As Long

    Set MstWb = ThisWorkbook
    ChDir "C:\Users\Desiree\Desktop\WCC Database"
    strFileName = Dir("Conso*.xls")

    'Import data from found files
    Do While Len(strFileName) > 0
    'Open book
    Set StrWb = Workbooks.Open(strFileName)
    'Grab rows and turn on consolidate
    Range("B17:B146").Copy
    Range("B" & Rows.Count).Consolidate
    'Put data in Master workbook
    MstWb.Activate
    Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
    NR = Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
    LR = Range("B" & Rows.Count).End(xlUp).Row
    Range(Cells(NR, "A"), Cells(LR, "A")) = sName
    'Get next file to open
    strFileName = Dir
    'Close current store file
    StrWb.Close False
    Loop

    End Sub


    I don't know where the error lies.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,609

    Re: MS Excel - VBA (Macros)

    Please see the rules regarding titles and code tags.
    Ben Van Johnson

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: MS Excel - VBA (Macros)

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1