Hi,
I would please like some help to improve the code of multiple loops.
I have a datasheet that has approx. 67 columns and between 1200 to 1500 rows.
I also have a report sheet that has only 20 columns.
The columns being searched are not regularly spaced, some might be consecutive, others several columns apart, but on the report sheet they are all consecutive.
I have created a simple loop that loops down the columns required, to extract the information required, from the datasheet, but with my limited knowledge I am switching between the two sheets on each hit and it is extremely slow.
I have a useform that gets two dates from the user - a 'from' date(f in the code below) and a 'to' date (t in the code below), and my logic is to loop down each of the 20 specific columns of the 67, and if the date falls between the two dates on the userform then to extract the information from the first column and transfer it to a 'Report' sheet and add it to the next row of the column, then switch back to the data sheet and carry on the loop of the datasheet!!! - very laborious
below is the code that works - but slowly!!
Any help would be greatly appreciated!!! - thanks in advance............
Dim i As Integer Dim LC As Long '*** Loop Counter on report sheet Dim LR As Integer '*** Last Row Dim k As Variant '*** House Number Sheets("Data").Select LR = Range("A2000").End(xlUp).Row '***** THIS BLOCK BELOW IS REPEATED 20 TIMES, JUST CHANGING THE COLUMN NUMBERS!! LC = 13 ' ** First row in report For i = 5 To LR Sheets("Data").Select '*** CHECK IF DATE IN CELL GREATER THAN BUT LESS THAN THE FROM AND TO DATES IN USERFORM '*** THE 'f' AND 't' VALUES ARE DATES DERIVED FROM THE USERFORM. If Cells(i, 6).Value > f And Cells(i, 6).Value < t Then k = Cells(i, 1).Value '*** IF IT IS GET THE NUMBER FROM COLUMN A Sheets("Reports").Select Cells(LC, 4).Value = k '*** PUT VALUE IN NEXT LINE LC = LC + 1 End If Next i