Very Basic VBA help needed urgently!

munshi1111

New Member
Joined
Jan 16, 2017
Messages
2
Hello all,

When it comes to VBA in excel, I will be the first to admit that I am a noob. I have come across a problem where I need help, urgently. So here is the situation:

I have three tabs (Orders, Logs, Completed) which contain data.
"Logs" has 7 columns (A-G)
Column G in "Logs" is doing a vlookup to find all the "y" values in "Orders" tab to show which orders a completed.

I need to find a code to cut and paste the rows of all "y" values I get in the "Logs" tab into the "Completed" tab. This is where I'm having an issue because I am getting these "y" values based on a vlookup.

After the row is moved, I need that empty row in "Logs" tab deleted. Any help??

I know this may come off as confusing, so let me know if I can make it easier to understand.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Munshi1111,

May not be what you're after but I've had similar issues when trying to collate data based on a particular column, to extract it into a different worksheet.

Basically, if you can insert a new column H (it will be hidden when we finish) and place a formula in column H

=ROW()

When you hide Column H, users will not see that it's there. But now you have a unique identifier to retrieve when you perform your VLOOKUP.

i.e. =VLOOKUP("y",$G$1:$H$999,2,FALSE) will give you the Excel Row number containing that record.


I'll have a look through some of my other projects, I may have some VBA that does something similar as well.
 
Upvote 0
Possibly...

Code:
Sub Filterit()
    With Sheets("Logs").Range("A1:G" & Sheets("Logs").Range("A" & Rows.Count).End(xlUp).Row)
        .AutoFilter Field:=7, Criteria1:="y"

        On Error Resume Next
        
        With .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
            .Copy Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Offset(1)
            .EntireRow.Delete
        End With
        
        On Error GoTo 0
        .AutoFilter

    End With
End Sub
 
Upvote 0
When I tried to run this, it worked fine for the first time. I changed the value to "y" again but this time the row did not delete after moving to the other sheet and got empty rows so the cells didn't move up. I got really excited when it worked the first time but unfortunately these problems came about.
 
Upvote 0
Are you sure the row didn't delete as there is no reason I can think of why it didn't if the correct row copied to the other sheet and the code deletes not clears :confused:

Are you sure that what remains isn't a row that is formulas and recalculating? if you are sure then you need to work out what the difference is between your old data and the new before we can give you a possible solution.
 
Upvote 0
Actually look at the question in the message box when you run the code below, check it, click ok and then post back whether there are any yellow cells left.

Code:
Sub Filterit()
    With Sheets("Logs").Range("A1:G" & Sheets("Logs").Range("A" & Rows.Count).End(xlUp).Row)
        .AutoFilter Field:=7, Criteria1:="y"

        On Error Resume Next
        
        With .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
            .Copy Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Offset(1)
            .Interior.ColorIndex = 6
            MsgBox "Are the correct rows highlighted?"
            .EntireRow.Delete
        End With
        
        On Error GoTo 0
        .AutoFilter

    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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