Consulting

Results 1 to 4 of 4

Thread: Importing data in consecutive rows

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    4
    Location

    Importing data in consecutive rows

    So I have a sheet with a list and another sheet where I want to move part of that list, that meets certain criteria, I am using IF and being able to move to the new sheet only the information that meets the criteria, but not in consecutive rows, so for example if the first matching item is in row 50, it will appear in row 50 on the new sheet, instead of the first data row below the header. I know it should be simple enough and I have seen a couple of things that might help with my issue here and there, but I get a bunch of different errors when I try those things.


    Currently it looks like this (I added just the part that is executing the task):


    temprows = Worksheets(S4).Cells(Rows.Count, 1).End(xlUp).Row
    For Count = 2 To temprows
    If Worksheets(S3).Cells(Count, 2) = "1 - Standard" Then
    Worksheets(S4).Cells(Count, 1) = Worksheets(S3).Cells(Count, 1)
    End If
    Next

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    i = 2
    temprows = Worksheets(S4).Cells(Rows.Count, 1).End(xlUp).Row 
    For Count = 2 To temprows 
        If Worksheets(S3).Cells(Count, 2) = "1 - Standard" Then 
            Worksheets(S4).Cells(i, 1) = Worksheets(S3).Cells(Count, 1)
            i=i+1 
        End If 
    Next
    BTW, Better to avoid variable names like "Count" which have a function in VBA
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Use Advancedfilter in this case.

  4. #4
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    4
    Location
    Thank you! it works as needed, and you're right about the variable names, changed that as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •