Quick Macro needed

pklimchuk

Board Regular
Joined
Oct 8, 2010
Messages
101
Hello Can someone help me with a Macro

I need a Macro;

If Y2 = "GGJKK", then what ever the value in W2 mulitipy by 2

but exclude the values that are ".20" ".18" ".16" ".14"
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Do you mean something like this?
Code:
Sub Test()
    I = [W2].Value
    If I <> 0.2 And I <> 0.18 And I <> 0.16 And I <> 0.14 And [Y2].Value = "GGJKK" Then [W2].Value = I * 2
End Sub
 
Upvote 0
Hi,
I'm sure there are more elegant ways of doing it but the following does work.
Code:
Sub Test1()
If Sheets(1).Cells(2, 25) = "GGJKK" Then
ans = Sheets(1).Cells(2, 23) * 2
    If Not ans = 0.2 And Not ans = 0.18 And Not ans = 0.16 And Not ans = 0.14 Then
        Sheets(1).Cells(4, 25) = Val(ans)
    End If
End If
End Sub

Good luck,

Alan
 
Upvote 0
OR
Code:
Sub Test()
Dim I As Integer
    I = [W2].Value
    If I <> 0.2 And I <> 0.18 And I <> 0.16 And I <> 0.14 And [Y2].Value = "GGJKK" Then [W2].Value = I * 2
End Sub
 
Upvote 0
Michael M: It worked fine for me with out declaring the variable on 2007, are earlier versions picky about having the declaration?
 
Upvote 0
How do i get it to go all the way donwn for the entire Spreadsheet

not just one sell

Sub Test()
I = [W2].Value
If I <> 0.2 And I <> 0.18 And I <> 0.16 And I <> 0.14 And [Y2].Value = "GGJYKK" Then [W2].Value = I * 2
End Sub
 
Upvote 0
Try this, untested
Code:
Sub Test()
Dim r As Long, lr As Long
lr = Cells(Rows.Count, "W").End(xlUp).Row
    For r = lr To 2 Step -1
        If r <> 0.2 And r <> 0.18 And r <> 0.16 And r <> 0.14 And Range("Y" & r).Value = "GGJYKK" Then Range("W" & r).Value = I * 2
        Next r
End Sub
 
Upvote 0
Try this, untested
Code:
Sub Test()
Dim r As Long, lr As Long
lr = Cells(Rows.Count, "W").End(xlUp).Row
    For r = lr To 2 Step -1
        If r <> 0.2 And r <> 0.18 And r <> 0.16 And r <> 0.14 And Range("Y" & r).Value = "GGJYKK" Then Range("W" & r).Value = I * 2
        Next r
End Sub

Hi, It didnt work

It changes all the values in W to 0 after multiplying
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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