if then else?

sufianmalik

Board Regular
Joined
May 7, 2002
Messages
128
hi there

importing a report into excel, it contains rows of numbers with subtotals.

all the rows where the number is between 40 and 60 must be changed to 40. All of these rows have a resource name and was using this in a do loop until blank. also need another do loop to keep going to each column until blank

all subtotals to remain untouched

all values greater than 40 to remain untouched.

i'm sure there's a much better way, if anyone can suggest?

Look forward to your response

Suf


Here's what i have so far....


Data:
sufian 40 70 40 40
bob 40 20 40 75
fred 45 50 31 56



Example code....

Sub between40and60()
'
Range("c5").Select

Do Until ActiveCell.Offset(1, 0).Value = ""

ActiveCell.Offset(0, 1).Select

If ActiveCell.Value > 40 And ActiveCell.Value <= 60 Then

ActiveCell.Value = 40

End If

Loop

Range("c5").Offset(1, 0).Select

Do Until ActiveCell.Offset(0, 1).Value = ""

If ActiveCell.Offset.Value > 40 And ActiveCell.Offset.Value <= 60 Then

ActiveCell.Offset.Value = 40

End If


Loop

ActiveCell.Offset(1, 0).Select





End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try:

Code:
Sub Test()
    Dim Cell As Range
    For Each Cell In Range("C5").CurrentRegion
        If IsNumeric(Cell.Value) And Cell.Value > 40 And Cell.Value <= 60 Then
            Cell.Value = 40
        End If
    Next Cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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