Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:26:09+00:00 2026-06-06T08:26:09+00:00

I have been looking at this for to long so I am tossing it

  • 0

I have been looking at this for to long so I am tossing it to those with more experience then I in hope of a copper or to of knowledge being tossed at me. The code runs with no errors.

The issue is that the second increment of the 1st loop overrides the first increments data range and so on. Loop 1 will populate rows 2:15. If I look at the address of lastrow it will show me the correct range of b16 as lastrow/cell in column to paste to , But as soon as the loop for the next objWorkBook runs it starts overwriting the fist increments cells rather then going to last row. I have a feeling i am missing something silly but it alludes me.

Any help or advice would be appreciated. I am relay interested in feed back. this will eventually process 100+ workbooks each adding roughly 1000 entries. I am concerned about the efficiency of my code. would using arrays speed things up? once things are caught up it will only process 2 workbooks a week. Again thank you for any pointer or advice your willing to share.

Option Explicit

Sub parse()

    Application.DisplayAlerts = False
    'Application.EnableCancelKey = xlDisabled

    Dim strPath As String, strPathused As String
    strPath = "C:\prodplan"

    Dim objfso As FileSystemObject, objFolder As Folder, objfile As Object

    Set objfso = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objfso.GetFolder(strPath)


    'Loop through objWorkBooks
    For Each objfile In objFolder.Files

        If objfso.GetExtensionName(objfile.Path) = "xlsx" Then

            Dim objWorkbook As Workbook
            Set objWorkbook = Workbooks.Open(objfile.Path)

            ' Set path for move to at end of script
            strPathused = "C:\prodplan\used\" & objWorkbook.Name

            'open WB to consolidate too
            Workbooks.Open "C:\prodplan\compiled\plancon.xlsx"


            'Range management WB
            Dim SRCwb As Worksheet, SRCrange1 As Range, SRCrange2 As Range, lastrow As Range

            Set SRCwb = objWorkbook.Worksheets("plan")
            Set SRCrange1 = SRCwb.Range("b6:i7")
            Set SRCrange2 = SRCwb.Range("k6:p7")

            'Range management destination WB
            Dim DSTws As Worksheet
            Set DSTws = Workbooks("plancon.xlsx").Worksheets("data")

            'start header dates and shifts copy from objworkbook to consolidated WB

            Set lastrow = Workbooks("plancon.xlsx").Worksheets("data").Range("b" & ActiveSheet.Rows.Count).End(xlUp).Offset(1, 0)

            SRCrange1.copy
            lastrow.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True
            Range(ActiveCell, Selection.End(xlDown)).Offset(0, -1).Value = objWorkbook.Name


            Set lastrow = Workbooks("plancon.xlsx").Worksheets("data").Range("b" & ActiveSheet.Rows.Count).End(xlUp).Offset(1, 0)

            SRCrange2.copy
            lastrow.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True
            Range(ActiveCell, Selection.End(xlDown)).Offset(0, -1).Value = objWorkbook.Name

            'Begin loop to copy content.
            Dim DSTheader As Range
            Set DSTheader = DSTws.Range("d1:bw1")
            Dim SRCheader As Range
            Set SRCheader = SRCwb.Range("a1:a110")

            Dim x As Variant
            Dim y As Variant

            Dim matchEXIT As Boolean
            matchEXIT = False

    For Each x In DSTheader
      For Each y In SRCheader

            Dim SRCrngCP1 As Range
            Set SRCrngCP1 = SRCwb.Range(y.Offset(0, 1).Address & ":" & y.Offset(0, 8).Address)
            Dim SRCrngCP2 As Range
            Set SRCrngCP2 = SRCwb.Range(y.Offset(0, 10).Address & ":" & y.Offset(0, 15).Address)

            If y > 0 Then

            If x = y Then

            Dim MyColumn As String
            Dim Here As String


            Here = DSTws.Range(x.Address).Address
            MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)

            Set lastrow = DSTws.Range(MyColumn & ActiveSheet.Rows.Count).End(xlUp).Offset(1, 0)

            SRCrngCP1.copy
            lastrow.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True

            Set lastrow = DSTws.Range(MyColumn & ActiveSheet.Rows.Count).End(xlUp).Offset(1, 0)

            SRCrngCP2.copy
            lastrow.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False, Transpose:=True

            If x = y Then matchEXIT = True
            If matchEXIT = True Then Exit For

    End If
    End If

        Next y

            matchEXIT = False
    Next x

     MsgBox x
            objWorkbook.Close False

            'Move proccesed file to new Dir
            Dim OldFilePath As String
            Dim NewFilePath As String

            OldFilePath = objfile 'original file location
            NewFilePath = strPathused ' new file location
            Name OldFilePath As NewFilePath ' move the file

        End If
            Set lastrow = Workbooks("plancon.xlsx").Worksheets("data").Range("b" & ActiveSheet.Rows.Count).End(xlUp).Offset(1, 0)
    Next

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:26:10+00:00Added an answer on June 6, 2026 at 8:26 am

    Ok so i figured it out after a nice long weekend away from it. With a Duh moment had

     'open WB to consolidate too
                Workbooks.Open "C:\prodplan\compiled\plancon.xlsx" 
    

    Inside the loop that was suppose to copy to it so at each loop it reset my copy to WB causing what looked like overwriting.

    I moved the open line out and the loop increments the paste to last cell with no issue. it did however break

     Range(ActiveCell, Selection.End(xlDown)).Offset(0, -1).Value = objWorkbook.Name
    

    Well sort of .. If I f8 down the code it works .. if I run the code it skips the line .. I dunno… .I will re post with another Question if I can’t figure it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I've just been looking at this too long. I have some data
I've been looking at this for too long and I've have lost all capacity
Dudes, been trying for very long time on solving this. I have been looking
I think I have been looking at this for too long. Why is this
I have been looking at this for a long time and finally decided to
Perhaps I have been looking at this for too long as I cannot find
I have been looking over this code for the past hour, I cant see
I have been looking all over for this. I have two seperate prpt files
I have been looking for an answer to this on Stack Overflow, but I
I have been looking for some time for this and I can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.