VBA For Each Cell In Range problem

Mladen82

New Member
Joined
Dec 20, 2018
Messages
8
Hi,

Im new in VBA world so I dont know how to fix this.

Dim rng As Range, cell As Range, tip As String
Set rng = Range("F2:F5000")
Set tip = Range("C2:C5000")
For Each cell In rng
If Value.tip = "TIP2EV" Then
cell.Value = cell.Value * 2
End If
Next cell

I want if cell in column C="TIP2EV" then cell in column F is cell.value*2

Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Not completely sure what you want to accomplish, but maybe this will get you in the right direction.

For Each cell In tip
If cell.Value = "TIP2EV" Then
cell.Offset(0, 3).Value = cell.Offset(0, 3).Value * 2
End If
 
Upvote 0
Hi Mladen82,

Welcome to MrExcel!!

Try this:

Code:
Option Explicit
Sub Macro1()

    Dim rng As Range, rngMyCell As Range
    
    Application.ScreenUpdating = False
    
    Set rng = Range("F2:F5000")
 
    For Each rngMyCell In rng
        If Range("C" & rngMyCell.Row) = "TIP2EV" Then
            rngMyCell.Value = rngMyCell.Value * 2
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True
 
End Sub

Regards,

Robert
 
Last edited:
Upvote 0
try

Code:
Sub test()
Dim cell As Range, trp As Range
Set trp = Range("C2:C5000")
For Each cell In trp
If cell.Value = "TIP2EV" Then
cell.Offset(, 3).Value = cell.Offset(, 3).Value * 2
End If
Next cell
End Sub
 
Upvote 0
Eliminates the flashing as items on the screen change !!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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