+ Reply to Thread
Results 1 to 4 of 4

Dynamic rows in selection

  1. #1
    Registered User
    Join Date
    10-23-2014
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    Dynamic rows in selection

    Hi,

    I am a beginner at VBA however after reading a book and watching many videos I started to work hard to create own macro that would speed-up my work in the office. I have the excel spreadsheet with the data retrieved from another spreadsheet. I have already sorted all values based on vlookup function however I want to cut and paste to different tab only rows having value found in vlookup, all #N/A" should stay in place. My value searching is conducted in column "K" row by row until macro reaches "N/A" in the row meaning no value was found. Just want to point that range is dynamic and number of rows is changing every day. I have written initial VBA code however is not working ... Can you please assist me with this matter?

    Sub cutt()
    Dim rng As Range
    lastRow = Cells(Rows.Count, 2).End(xlUp).Row
    Set rng = Range("A1:K" & lastRow)
    rng = Range("A1:K" & lastRow).Select


    Range("A2").Select
    For i = 1 To rng
    If Cells(i, 11).Text <> "#N/A" Then
    Cells(i, 11).EntireRow.Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Select
    End If
    Next

    End Sub

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Dynamic rows in selection

    Welcome to the board!

    Please use code tags when posting code.

    In your studies, look for Guru's who teach using Range instead of Selection. Code execution is faster and you won't have as many suprises. Yes, I know, Excel generates code using Selection, but it has to since everything is created without defined values.

    In your code, you're not pasting anything.
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    10-23-2014
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    Re: Dynamic rows in selection

    Hello David,

    Thanks a lot for your assistance, it works now! What I want to do next is delete previously copied rows and shift remainings up. It should be pretty the same code however I encountered some problems. Will try to figure out it however if I fail then I would appreciate your help once again,
    Thanks mate!

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Dynamic rows in selection

    Please Login or Register  to view this content.

+ 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. [SOLVED] Change selection of cells to selection of rows
    By olwy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2014, 11:38 AM
  2. VBA Dynamic Range selection
    By Arrabonae in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 05:09 AM
  3. dynamic row selection
    By tiggle in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-17-2011, 04:04 PM
  4. VBA Dynamic Selection
    By AJMorgan591 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2005, 08:05 AM
  5. Object Type of a selection... counting rows in a selection
    By Acid-Sky in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2005, 05:05 AM

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