Code Please That Could Save Me Hours

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I need a code that will look at any data that is in column AG and copy it 1 row up and 5 columns to the left (AB) but only if the destination cell has NYA in it. Is this possible please? Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub TaggaTaggaTagga()
    With ActiveSheet
        .AutoFilterMode = False
        With Intersect(.Columns("AB"), .UsedRange)
            .AutoFilter Field:=1, Criteria1:="=NYA"
            .SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=R[1]C[5]"
            .AutoFilter
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
Code:
Sub TaggaTaggaTagga()
    With ActiveSheet
        .AutoFilterMode = False
        With Intersect(.Columns("AB"), .UsedRange)
            .AutoFilter Field:=1, Criteria1:="=NYA"
            .SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=R[1]C[5]"
            .AutoFilter
            .Value = .Value
        End With
    End With
End Sub

It didnt quite work. It did copy up 1 and across 5 but it put zeros in all the other cells in AB which it shouldnt have touched. (A lot of the rows in column AG will be blank) so it only needs to copy across only the cells that have data in them.
 
Upvote 0
I have also noticed that is copying across to cells that have data other than NYA, when it should do nothing
 
Upvote 0
Code:
Sub TaggaTaggaTagga()
    With ActiveSheet
        .AutoFilterMode = False
        With Intersect(.Columns("AB:AG"), .UsedRange)
            .AutoFilter Field:=1, Criteria1:="=NYA"
            .AutoFilter Field:=6, Criteria1:="<>"
            .Resize( ,1).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=R[1]C[5]"
            .AutoFilter
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
It has now come up with an error of a red cross with 400 next to it.
 
Upvote 0
Code:
Sub TaggaTaggaTagga()
    With ActiveSheet
        .AutoFilterMode = False
        With Intersect(.Columns("AB"), .UsedRange)
            .AutoFilter Field:=1, Criteria1:="=NYA"
            .SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=IF(LEN(R[1]C[5]),R[1]C[5],"")"
            .AutoFilter
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
What is the error description?
What line is highlighted when the error occurs?
Is the sheet that this applies to the active sheet?
 
Upvote 0
It is just a box saying Microsoft Visual Basic with a red cross and 400 in it. No line is highlighted I just press ok and it seems to finish but nothing seems to have been done. I have got the sheet 'active' that I want the code to work on when I run the code.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

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