I gave it a whirl and tried to comment out the filtering.
After taking out the filtering, I get an error on the line:
'Static vc As Range: Set vc = ur.Offset(1, 0).Resize(ur.Rows.Count - 1, ur.Columns.Count).SpecialCells(xlCellTypeVisible)
I don't understand that line enough to fix it.
I played with the code and it copies the first sheet of data to the second sheet which is great.
But what it needs to do is realize that there are 164 lines(which can change, it's not always going to be 164) of ID#'s to create rows for.
It has to take into consideration that the id's will increment. The ID# column and the Serial # column will not be identical between each row of data, but most of the rest of the row's data will be the same as the row above it.
Sub CopyIDRowsMacro_for_foolios()
'If WorksheetFunction.CountA(ActiveSheet.Cells(2, 1).EntireRow) < 2 Then ActiveSheet.Cells(2, 1).EntireRow.Delete xlShiftUp
Static ur As Range: Set ur = ActiveSheet.UsedRange
'ur.AutoFilter Field:=1, Criteria1:="<>"
'With ActiveSheet.AutoFilter.Sort
' .SortFields.Clear
' .SortFields.Add Key:=ur.Resize(ur.Rows.Count, 1)
' .Header = xlYes
' .Apply
'End With
'Static vc As Range: Set vc = ur.Offset(1, 0).Resize(ur.Rows.Count - 1, ur.Columns.Count).SpecialCells(xlCellTypeVisible)
Static vc As Range
Set vc = ur
vc.Copy Sheets("Sheet2").[A2]
'ur.AutoFilter
End Sub
The sorting is a very cool feature but not necessary. Actually, it confuses me further so I tried to leave it out.
Thanks for showing me your idea. I am stuck with what I've pasted here since I don't know how to leave out the header column in copying the pages data.
I still believe a do while loop is necessary to create the rows of data on the next sheet considering how many ID#'s there are.
I will keep at this in the meantime. Thank you.
EDIT:
My uploaded workbook will create confusion. I am sorry about that.
I should have separated the ID# column from the rest of the columns of data on the Sheet1 to be copied to Sheet2.
It should really look more like:
Serial #'s Info1 Info2
300456987 Desc color
4325425 Desc color
and then separately on Sheet1 there should be a column that identifies the range of ID#'s:
Which would be 174 ID#'s(rows of data that have the serial # and info1 and info2) into the second sheet.
So, there is going to be two cell's on Sheet1 that identify how many ID#'s are going to be created and copied to Sheet2.
The copy function will take an ID# and it's associated data to include a serial# and info1 and info2 and paste that information onto a row in Sheet2.
In hopes of simplifying this even more, I am thinking I can take one cell(one row of data) that would include info1 and info2 and have that repeatedly copied and pasted for each ID#'s row that is created.
I can set the Serial #'s to increment along with the ID#'s as well.
So an ID# will increment from 10 to 11 to 12 and so on. The serial # that coincides with the ID# can increment as well from 2980 to 2981 to 2982.
idVar = nmbrOfIds
idVar2 = nmbrOfSers
idVarFin = 0
do while idVarFin < idVar
Sheet2.cell(2,1) = idVarBegIDNumbr
Sheet2.cell(2,2) = Sheet1.cell(10,12) 'cell with info1
Sheet2.cell(2,2).nextRow
idVar += 1
idVarBegIDNumbr += 1
'serial# code to match id# code
This is just my imagination of how it would work. I don't know what the exact coding of this is yet.
I will try to work on making two variables that will increment based on the number of ID#'s. One variable will hold the beginning ID# and the other will hold the beginning Serial #.
Then I will add code that will check if the previous cell has a serial#. If so, copy cell data from sheet1 info1 to it.
That just might work.
Bookmarks