eliminate condition if range Greater and less than in VBA code

AndyJR

Board Regular
Joined
Jun 20, 2015
Messages
90
Hi,
I'm using a VBA code that copy reports. but the code have 2 conditions
Condition 1 -> If greater or less than
Condition 2 -> Sort report by descending Date (*)

Condition 2 means that for example: if perhaps i've copy yesterday report (is going to have yesterday date) So when i run the code for today it will scroll down yesterday report range and it will copy the the new one on top of yesterday report. then at all the time the report will display many reports with descending date.

What i need is to eliminate the condition 1, because i feel that its take longer and i think is not necessary anymore. I've try but i'm getting error , i might missing a word, point, comma or something.

This is the code with correct range.
Note: the condition 1 problem start with value greater than >5 and less than <100


Code:
 Sub STRep_1()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False


Sheets("ST1").Select

Dim j As Long, lr As Long 
For j = 4 To 83
          
      If Cells(j, 359).Value > 5 And Cells(j, 359).Value < 100 Then _
          Cells(Rows.Count, 147).End(xlUp).Offset(1).Resize(, 50).Value = Cells(j, 359).Resize(, 50).Value
    
    Next j
    lr = Range("EV" & Rows.Count).End(xlUp).Row
    With Range("EQ2:GN" & lr)
         .Sort key1:=[EV3], order1:=xlDescending, Header:=xlYes
   
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True


   End With
   End Sub


Thanks in advance
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

problem Solved
(i have the same code 20 times applied to different range)
On each code I delete the snipped
Rich (BB code):
 > 5 And Cells(j, 359).Value < 100 

previously on the deletion was including the "Then _ " word., and of course i was getting error (my mistake.)

And to make code calculation Fast i set the Excel Option->Formula-> Manual
Also at top of each code i left the snipped -> applications-> Screen Updating, Calculation, Enable Event as False
and delete it the same snipped with True word located at the bottom, Then at the last code #20 i added a macro to call Calculation (equivalent at F9 key)
Calculation Time was reduced from 15 minutes to less than a minute.

Here is the modified code:
Rich (BB code):
Sub STRep_1()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False


Sheets("ST1").Select

Dim j As Long, lr As Long 
For j = 4 To 83
          
      If Cells(j, 359).Value Then _
          Cells(Rows.Count, 147).End(xlUp).Offset(1).Resize(, 50).Value = Cells(j, 359).Resize(, 50).Value
    
    Next j
    lr = Range("EV" & Rows.Count).End(xlUp).Row
    With Range("EQ2:GN" & lr)
         .Sort key1:=[EV3], order1:=xlDescending, Header:=xlYes
   
   End With 
End Sub



Thank you and have beautiful blessed day !!
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top