Inputbox To prompt Start of Data Range

  • Hi All,


    I have a code which lets me merge sheets courtesy a fellow forum member.


    The below snippet of the code merges the sheets in a given workbook in case data in each sheet starts from row 1 and cell a1.


    I modify it as per the scenario....if the data starts in row 3 then I modify Rows(1).copy to Rows(3).copy and [a1].CurrentRegion to [a3].CurrentRegion


    Is it possible to have an inputbox which lets the user decide where the data starts by providing these inputs without having to modify the code?


    Thanks!


    Code
    With .Sheets(1)
                For i = 2 To Sheets.Count
                    Sheets(i).Rows(1).Copy .Rows(1)
                    lRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
                    Sheets(i).[a1].CurrentRegion.Offset(1).Copy .Cells(lRow, 1)
                Next
  • Re: Inputbox To prompt Start of Data Range


    Try this:


    Sub foo()

    Code
    Dim x As Long
    x = InputBox("What row for data?")
    With .Sheets(1)
        For i = 2 To Sheets.Count
            Sheets(i).Rows(x).Copy .Rows(1)
            lRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Sheets(i).[a & x].CurrentRegion.Offset(1).Copy .Cells(lRow, 1)
        Next
  • Re: Inputbox To prompt Start of Data Range


    Thanks Alan!


    I am getting a Run Time error '424': Object Required....below line is highlighted


    Code
    Sheets(i).[a & x].CurrentRegion.Offset(1).Copy .Cells(lRow, 1)


    Thanks.

  • Re: Inputbox To prompt Start of Data Range


    possibly

    Code
    x = InputBox("What row for data?")
    
    
    With Sheets(1)
        For i = 2 To Sheets.Count
            Sheets(i).Rows(1).Copy .Rows(1)
            lRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Sheets(i).[a1].CurrentRegion.Offset(x).Copy .Cells(lRow, 1)
        Next
        End With


    this line

    Code
    Sheets(i).Rows(1).Copy .Rows(1)

    just copies over the top of the existing data?

  • Re: Inputbox To prompt Start of Data Range


    Thanks Pike,


    Below is complete code in its existing form.


    What this does is:
    1)Prompts the user to select the target file from which sheets are to be merged.
    2)Combines/merge all data sheets into one in a new workbook with tab name as today's date and time.
    3)Everyday/everytime this macro is run a new worksheet with today's date and time as name will get populated alongside yesterday's sheet.


    So nothing is copied as such because there won't be existing data.



  • Re: Inputbox To prompt Start of Data Range


    Hi Pike,


    If I make the change you suggested, only the 7th row from each sheet is copied.



    Attaching examples. forum.ozgrid.com/index.php?attachment/66537/ sheet is the one from where I execute the macro from, while forum.ozgrid.com/index.php?attachment/66538/ is my sample data from which sheets are to be merged.


    In this example, data to be copied starts from row 7.


    Thanks.

  • Re: Inputbox To prompt Start of Data Range


    Sorry if I have ended confusing you. What I meant was that the contiguous data set may start from any row(in the scenario above its the 7th row).


    The code in its original form above works successfully if the data to be merged from each sheet starts from the 7th row and the entire current region is copied.


    However there maybe times where the data will start from the 3rd or 4th row or for that matter any row. So I want to try and provide the user the option to provide that as a variable rather than amend the code for each scenario.


    So basically I want all contigious(current region) content in the sheets to be copied. My intent is not copy just the row specified.


    Thanks

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!