+ Reply to Thread
Results 1 to 5 of 5

VBA to import cells from excel with blank rows between them

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    VBA to import cells from excel with blank rows between them

    Please, I need a VBA to import cels like A1:E4 to a main file that will receive all with a blank row between them, like:

    2151 3966 223 2020 21522
    32122 8521 5554 333 55581
    -209 1675 -113 -1354 111160
    -421 249 -281 -3041 166739

    -845 413 -617 -6415 277897
    -1057 495 -785 -8102 333476
    -1269 577 -953 -9789 389055
    -1481 659 -1121 -11476 444634

    -1905 823 -1457 -14850 555792
    -2117 905 -1625 -16537 611371
    -2329 987 -1793 -18224 666950
    -2541 1069 -1961 -19911 722529

    All the imported files are in the same folder with sequential names.

    I did a search and found this:
    http://www.ozgrid.com/forum/showthread.php?t=141650
    As well as other solutions, but none more specific.

    Please, make the code in such a way that I may customize it, changing:
    the folder with the files to be imported;
    A1:E4 to G67:M89 or so;
    the blank lines to 0, 3, 5 or more;
    the first cell, instead of A1, to T66 or another.

    I hope this will help a lot of people with problems like this, too.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,706

    Re: VBA to import cells from excel with blank rows between them

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: VBA to import cells from excel with blank rows between them

    Sure, excuse me.

    To make it more clear, eventually, instead of data, I may import the result of formula, but not the formula, too.

    Here it is:
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-19-2013
    Location
    brazil
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: VBA to import cells from excel with blank rows between them

    I have found this and I want to share with ALL of you:

    Sub PasteCellsFromOtherFiles()

    Dim Pasta As String
    Dim Arquivo As String
    Dim linha As Integer

    'inputbox to set the number of lines to skip between pasted sections
    linha = InputBox("Enter how many rows to skip between blocks", "Number of rows to skip")

    'opens a window to select the folder where the files are
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
    Pasta = .SelectedItems(1)
    End With

    'association of the first file in the selected folder to the variable "arquivo"
    Arquivo = Dir(Pasta & "\" & "*.xls*")

    'repeat command that copies files
    Do
    Workbooks.Open Pasta & "\" & Arquivo

    'copy and paste cells according to the variable "linha" in a line below the last line completed
    ActiveSheet.UsedRange.Copy _
    ThisWorkbook.Sheets("Sheet1").Range("A" & Cells.Rows.Count).End(xlUp).Offset(1 + linha, 0)
    Workbooks(Arquivo).Close

    'associate the next file in the selected folder to the variable "arquivo"
    Arquivo = Dir
    Loop While Arquivo <> ""
    Application.CutCopyMode = False

    'transform collage in paste values
    Cells.Select
    Selection.Copy
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    End Sub
    Last edited by dualaudio454252; 04-11-2014 at 07:02 PM. Reason: I want to share with everybody

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,706

    Re: VBA to import cells from excel with blank rows between them

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problems with Blank cells on a CSV when i import
    By ataahuamami in forum Excel General
    Replies: 1
    Last Post: 03-18-2014, 09:06 PM
  2. [SOLVED] Inserting a specific number of blank rows between cells - Excel 2007
    By excelactuary in forum Excel General
    Replies: 3
    Last Post: 03-06-2013, 11:54 AM
  3. Replies: 2
    Last Post: 10-08-2012, 05:37 AM
  4. Replies: 2
    Last Post: 04-29-2009, 12:07 PM
  5. import with blank rows
    By ceemo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2006, 05:02 AM

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