I have a matrix-worksheet that is approximately 100x100 cells. May grow to 100x400
I need to write a macro that cycles through all the cells and if it finds a specific value, it will copy the cell value to a new table. Speed is a problem right now. Suggestions for improvements appreciated. Only a small percentage of the cells actually contain needed data.
This spreadsheet contains a lot of formulas (index, match, etc), so I wonder if the macro is slowed by recalculation on the worksheets??
Note: I am not a programmer or excel expert.
Current code:
*****
Sub copymatrix()
Dim i,j,counter as integer
Dim TestValue as Single
Dim tblsource, tblDestination as objects
'//Begin Code
Set tblsource = Worksheets("Sheet1")
Set tblDestination = Worksheets("Sheet2")
i,j,counter=1 '//initialize counters
'// Loop through the matrix
for i = 1 to 100 '//note: i actually use variables to set lower/upper loop bounds.
for j = 1 to 100
Testvalue=tblSource.Cells(i,j).value
if TestValue = "LogicalTest" then
tblDestination.Cells(1,counter)=TestValue
tblDestination.Cells(2,counter)=Counter
tblDestination.Cells(3,counter).value=TestValue+5
counter=counter+1
endif
next j
next i
end sub
Bookmarks