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 8516673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:29:40+00:00 2026-06-11T05:29:40+00:00

My Goal: To get all data about the same subject from multiple reports (already

  • 0

My Goal: To get all data about the same subject from multiple reports (already in the same spreadsheet) in the same row.

Rambling Backstory: Every month I get a new datadump Excel spreadsheet with several reports of variable lengths side-by-side (across columns). Most of these reports have overlapping subjects, but not entirely. Fortunately, when they are talking about the same subject, it is noted by a number. This number tag is always the first column at the beginning of each report. However, because of the variable lengths of reports, the same subjects are not in the same rows. The columns with the numbers never shift (report1’s numbers are always column A, report2’s are always column G, etc) and numbers are always in ascending order.

My Goal Solution: Since the columns with the ascending numbers do not change, I’ve been trying to write VBA code for a Macro that compares (for example) the number of the active datarow with from column A with Column G. If the number is the same, do nothing, else move all the data in that row (and under it) from columns G:J down a line. Then move on to the next datarow.

I’ve tried: I’ve written several “For Each”s and a few loops with DataRow + 1 to and calling what I thought would make the comparisons, but they’ve all failed miserably. I can’t tell if I’m just getting the syntax wrong or its a faulty concept. Also, none of my searches have turned up this problem or even parts of it I can maraud and cobble together. Although that may be more of a reflection of my googling skill 🙂

Any and all help would be appreciated!

Note: In case it’s important, the columns have headers. I’ve just been using DataRow = Found.Row + 1 to circumvent. Additionally, I’m very new at this and self-taught, so please feel free to explain in great detail

  • 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-11T05:29:42+00:00Added an answer on June 11, 2026 at 5:29 am

    I think I understand your objective and this should work. It doesn’t use any of the methodology you were using as reading your explanation I had a good idea how to proceed. If it isn’t what you are looking for my apologies.

    It starts at a predefined column (see FIRST_ROW constant) and goes row by row comparing the two cells (MAIN_COLUMN & CHILD_COLUMN). If MAIN_COLUMN < CHILD_COLUMN it pushes everything between SHIFT_START & SHIFT_END down one row. It continues until it hits an empty row.

    Sub AlignData()
      Const FIRST_ROW As Long = 2       ' So you can skip a header row, or multiple rows
      Const MAIN_COLUMN As Long = 1     ' this is your primary ID field
      Const CHILD_COLUMN As Long = 7    ' this is your alternate ID field (the one we want to push down)
      Const SHIFT_START As String = "G" ' the first column to push
      Const SHIFT_END As String = "O"   ' the last column to push
    
      Dim row As Long
      row = FIRST_ROW
      Dim xs As Worksheet
      Set xs = ActiveSheet
      Dim im_done As Boolean
      im_done = False
      Do Until im_done
        If WorksheetFunction.CountA(xs.Rows(row)) = 0 Then
          im_done = True
        Else
          If xs.Cells(row, MAIN_COLUMN).Value < xs.Cells(row, CHILD_COLUMN).Value Then
            xs.Range(Cells(row, SHIFT_START), Cells(row, SHIFT_END)).Insert Shift:=xlDown
            Debug.Print "Pushed row: " & row & " down!"
          End If
          row = row + 1
        End If
      Loop
    End Sub
    

    I modified the code to work as a macro. You should be able to create it right from the macro dialog and run it from there also. Just paste the code right in and make sure the Sub and End Sub lines don’t get duplicated. It no longer accepts a worksheet name but instead runs against the currently active worksheet.

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

Sidebar

Related Questions

I'm basically trying to get all touch event data from something like a system
My goal is to get various SEO-relevant information for various sites. Basically all the
My goal is to get a Time instance from a DateTime instance This has
my simple goal is following: i would get the news feed from a facebook
Goal : Get a screenshot of a map with overlays(MKOverlayView) as well as the
How do i do that? Actually my main goal is to get which checkbox
Goal My goal is to to get Twitter Bootstrap to worth with my Play
The goal is to let users login via Twitter, get OAuth token and secret
Goal: Produce an Excel document with information from 3 associated models that is similar
Trying to get a simple COUNT from a table that takes a couple of

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.