PDA

View Full Version : [SOLVED] Importing data in consecutive rows



j16n
07-21-2017, 01:43 PM
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

mdmackillop
07-22-2017, 02:58 AM
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

snb
07-22-2017, 04:23 AM
Use Advancedfilter in this case.

j16n
07-24-2017, 09:44 PM
Thank you! it works as needed, and you're right about the variable names, changed that as well.