My macro not working

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi

I have the following macro and wondered what ive done wrong as its not moving data when there is data with word "fare" in column E.

Sub MoveData()
Dim ws As Worksheet
Dim lr As Long, i As Long

Application.ScreenUpdating = False

Set ws = Worksheets("Sheet1") 'Data Sheet
lr = ws.Cells(Rows.Count, "E").End(xlUp).Row

For i = 1 To lr
If UCase(ws.Cells(i, "E").Value) = "Fare" Then
ws.Range("E" & i & ":AS" & i).Cut ws.Range("G" & i)
End If
Next i
Application.ScreenUpdating = True
End Sub

Any ideas?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
UCASE converts all entries to UPPER case. So it can never equal "Fare".
Try:
Code:
[COLOR=#333333]If UCase(ws.Cells(i, "E").Value) = "[/COLOR][COLOR=#ff0000]FARE[/COLOR][COLOR=#333333]" Then[/COLOR]
 
Upvote 0
As Joe4 has pointed out the reason your code isn't working is that Fare needed to be all capitals but also you don't need the End If as you are only doing a single test so it can all go on the one line i.e.

Code:
Sub MoveData()
    Dim ws As Worksheet
    Dim lr As Long, i As Long

    Application.ScreenUpdating = False

    Set ws = Worksheets("Sheet1")                'Data Sheet
    lr = ws.Cells(Rows.Count, "E").End(xlUp).Row

    For i = 1 To lr
        If UCase(ws.Cells(i, "E").Value) = "FARE" Then ws.Range("E" & i & ":AS" & i).Cut ws.Range("G" & i)
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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