largeselection
Active Member
- Joined
- Aug 4, 2008
- Messages
- 358
I have a workbook where there are various groups of cells where users enter values. I have code which translates that worksheet into a nice clean data table. Essentially the code loops through the defined ranges and checks every cell to see if there is a value > 0. If there is a positive value, then it adds it to the data table on the next tab and lists the row # and col # where that value is found. Then it moves onto the next one until it has checked all the cells in the defined range. The reason why I ask if the "If" check slows things down is because it is taking a long time to complete the process. There are approx 18,000 cells in the defined range, in my test there were approx 11,000 that actually had a value > 0. So it took about 10 minutes to complete the process. My original thinking is that it would be faster since it is checking 18,000 cells that it would be able to immediately skip 7,000 since they are blank. But now I'm thinking it might not be faster since rather than just doing the process of listing the value and the row/column associated for every cell it has to stop to do that check first and maybe that's slowing it down.
Any thoughts on if this is helpful or not? Also, if anyone has a better suggestion on how to get this data into a data table that would be helpful too. Example of sheets and code is below:
Data on sheet 1 looks like:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]19[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"]24[/TD]
[/TR]
</tbody>[/TABLE]
Desired Output on sheet 2 looks like:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Row[/TD]
[TD="align: center"]Col[/TD]
[TD="align: center"]Value[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]2[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]4[/TD]
[TD]19[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]4[/TD]
[TD]24[/TD]
[/TR]
</tbody>[/TABLE]
Any thoughts on if this is helpful or not? Also, if anyone has a better suggestion on how to get this data into a data table that would be helpful too. Example of sheets and code is below:
Data on sheet 1 looks like:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]19[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"]24[/TD]
[/TR]
</tbody>[/TABLE]
Desired Output on sheet 2 looks like:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Row[/TD]
[TD="align: center"]Col[/TD]
[TD="align: center"]Value[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]2[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]4[/TD]
[TD]19[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]4[/TD]
[TD]24[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Set tWS = ActiveSheet Set iRange = Range("Data.Grid")
Sheets("DATA").Range("A3:BZ75000").ClearContents
lRow = Sheets("DATA").Range("A" & Rows.Count).End(xlUp).Row + 1
For Each iCell In iRange.Cells
If Len(iCell.Value) > 0 Then
iCol = iCell.Column
iRow = iCell.Row
With Sheets("DATA")
.Cells(lRow, 1).Value = iRow
.Cells(lRow, 2).Value = iCol
.Cells(lRow, 3).Value = iCell.Value
End With
lRow = lRow + 1
End If
Next