vba help

dani1

Board Regular
Joined
Mar 23, 2010
Messages
90
hi experts!

i Im starting to learn VBA/Macros and Im having trouble
Can some one help me with If statements.
In the workbook sheet 2 I have a macro for an If statement but I cant figure out how to auto fill in the d3-d12 using the macro.

here is my marco that i want to auto fill in cells D2:D12

Sub If_()
If Range("C2") >= 300000 Then
Range("D2") = 0.3 * Range("C2")
ElseIf Range("C2") <= 300000 Then
Range("D2") = 0.15 * Range("C2")

End If

End Sub
Ive tried this one and doesnt work

Sub If_()
If Range("C2:C12") >= 300000 Then
Range("D2:D12") = 0.3 * Range("C2:C12")
ElseIf Range("C2") <= 300000 Then
Range("D2:D12") = 0.15 * Range("C2:C12")
End If

End Sub


how can we solve dis problem?
 

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
Something like this maybe

Code:
Option Explicit

Sub If_()
Dim r As Range

Application.ScreenUpdating = False

For Each r In Range("C2:C12")
    If r.Value >= 300000 Then
        r.Offset(0, 1) = r.Value * 0.3
    Else
        r.Offset(0, 1) = r.Value * 0.15
    End If
Next r

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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