Hi! My problem is a little complicated (for me! ...noob). I'll try to simplify my explanation a little, but feel free to ask questions if I do a cruddy job. Here it is:
I have a workbook open with four worksheets in it. Each worksheet has several tables, one on top of the other with a blank row in between, all starting in column A. I have an array I would like to use to populate the various columns of the tables, and the array is updated by a separate program (which actually works).
The number of columns in each table will always be the same; however the number of rows can change. The number of rows in the table should equal the number of rows in the array from the first program. I'm currently writing a Display() sub which should populate the tables using my array. I don't want to recreate the table headings every time I run the program, so I would like to have Display() detect and accomplish several things before writing any information. First, I want it to find the appropriate table by its title ("Schedule A", "Schedule B", and so on). Then I want it to find the next table underneath it (if one exists), and count the number of rows between the two. If the number of rows between them does not equal the number of rows in the array, I would like the program to insert blank rows until they are equal. This way it will not overwrite the title or headings of the following table.
I was able to get this to work when I tried filling in just one schedule in isolation, but once I wrote it for the additional tables, the program added infinite rows. Here's what I was using:
What can I do? There has to be a better way. Thank you in advance!! Any help is suuuuuuper appreciated.
I have a workbook open with four worksheets in it. Each worksheet has several tables, one on top of the other with a blank row in between, all starting in column A. I have an array I would like to use to populate the various columns of the tables, and the array is updated by a separate program (which actually works).
The number of columns in each table will always be the same; however the number of rows can change. The number of rows in the table should equal the number of rows in the array from the first program. I'm currently writing a Display() sub which should populate the tables using my array. I don't want to recreate the table headings every time I run the program, so I would like to have Display() detect and accomplish several things before writing any information. First, I want it to find the appropriate table by its title ("Schedule A", "Schedule B", and so on). Then I want it to find the next table underneath it (if one exists), and count the number of rows between the two. If the number of rows between them does not equal the number of rows in the array, I would like the program to insert blank rows until they are equal. This way it will not overwrite the title or headings of the following table.
I was able to get this to work when I tried filling in just one schedule in isolation, but once I wrote it for the additional tables, the program added infinite rows. Here's what I was using:
Code:
'Find first heading row for desired table, name the row "displayrow"
displayrow = .Columns(1).Find(What:=WS & ": Schedule " & Sch, After:=.Cells(2, 1), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False).Row
'Make correct number of rows between schedules
Do Until nextrow - displayrow = k + 3
'(the first table begins in row 3, k is the number of rows I want in the table)
nextrow = .Columns(1).Find(What:="Schedule ", After:=.Cells(displayrow, 1), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False).Row
If nextrow - displayrow < k + 3 Then
.Rows(displayrow + 2).EntireRow.Insert
Else: Exit Do
End If
Loop
What can I do? There has to be a better way. Thank you in advance!! Any help is suuuuuuper appreciated.