Results 1 to 2 of 2

How can I copy data in a column until the next cell is ""?

Threaded View

Allan91 How can I copy data in a... 12-22-2020, 06:25 AM
AliGW Re: Do Until... 12-22-2020, 06:26 AM
  1. #1
    Registered User
    Join Date
    12-19-2020
    Location
    Turkey
    MS-Off Ver
    2019
    Posts
    19

    How can I copy data in a column until the next cell is ""?

    Hi guys,

    I have written this code that draws data from one sheet to another (Please see the code below). I use a do until loop to do this. But I have 2 problems with it.

    1. I have a formula commanding to return "" in case of an error in the original data and I don't want the code to draw the empty data (meaning the ones with ""). Hence "End(xlUp).Row" is not cutting it for me. How can I achieve this?
    2. In the code, the copy and paste selection ranges are supposed to go to the end but it just copies the first row of the selected columns and that's it.

    It's crucial for me to stop copying if the cell is "" and not absolute blank because I will use the copied data to create a pivot table. If the data with "" formula is there, it will pick it up as data and include it in the table, ruining my slicers.

    Thank you very much in advance!

    Sub GetData()
    
    Dim Lastrow As Integer
    Lastrow = Worksheets("Clean Data_I").Cells(Rows.Count, 1).End(xlUp).Row
    
    Dim Counter As Integer
    Counter = 1
    
    Do Until Counter = Lastrow + 1
    'Worksheets("Clean Data_I").Range("U" & Counter & ":Y" & Counter).Copy
    Worksheets("Clean Data_I").Range("U1:Y500").Copy
    
    Dim LastRowDest As Integer
    LastRowDest = Worksheets("Clean Data_I2").Cells(Rows.Count, 1).End(xlUp).Row
    'Worksheets("Clean Data_I").Range("A" & Counter & ":E" & Counter).PasteSpecial xlPasteValues
    Worksheets("Clean Data_I2").Range("A1:E500").PasteSpecial xlPasteValues
    
    Counter = Counter + 1
    Loop
    
    Worksheets("Clean Data_I2").Columns.AutoFit
    
    
    End Sub
    Last edited by Allan91; 12-22-2020 at 06:30 AM. Reason: Title Clarification

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA picked the wrong column when specifying Range("B" & lastrow)
    By lynnsong986 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-05-2020, 07:34 AM
  2. Ignore "if" formula for Lastrow function
    By bsrivatsa in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-13-2018, 03:44 PM
  3. [SOLVED] Using "lastRow" to create dynamic code
    By NatalieW12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2017, 05:29 AM
  4. [SOLVED] Need help modifying multiple range code to include LastRow ("B2:B10",..) -> ("B2:B" & LR.)
    By sureng20 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2017, 09:31 AM
  5. Trying to improve speed of Index match, want to lookup "A1:A" & lastrow
    By OTWarrior in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 05-11-2017, 12:38 PM
  6. [SOLVED] Adding "Lastrow" function to these formulas:
    By Chad Bateman in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-25-2015, 10:59 PM
  7. How to transpose data into range ("A1:G" & lastrow)
    By jasondu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2012, 10:39 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