Delete Entire Rows That Have Multiple Matching Cells - vba

I created a macro that will copy over some information from one sheet in my workbook to another to match some criteria so I may import the info into a program. Only problem is after the macro runs, there are some blank rows and a couple duplicates. I have 12 columns of info but I would like to have the macro look at and compare entries in columns D,E,F,G and L with the row above them. So D2,E2,F2,G2 and L2 would be compared to D1,E1,F1,G1 and L1. IF all five of the entries in these cells match that of the previous row, then delete the entire row.
I've found some codes that match one cell or looks for duplicates in a certain column but nothing to look and match multiple columns and I'm so new to this that I'm having trouble even getting started.
Any and all input is welcome.

You're going to have to put in the logic of your program yourself but use something like:
worksheets("Sheet1").range("A1").offset(i, 0).resize(1, colnum).delete Shift:=xlUp
An easy way to find the commands you need is to record a macro and see what Excel uses to build that macro.

Related

Look for a word of column 1 and then search that word in another column of another excel sheet and use the adjacent information to fill the cell

I am trying to organize the data into one sheet. I am looking for a way through which I will be able to extract the potential failure mode from 2nd sheet to the first sheet. The key point is that the potential failure mode should match with its respective component. So the list of components is mentioned. A way through which Potential failure modes of that respective component is detected in another excel sheet and the information which is available in the adjacent column to be extracted on the first sheet.
Your problem is going to be solved with the function =VLOOKUP
Since you are hiding your column and sheet names, I am making some assumptions (assuming the first pic is called Sheet2 PAF is on column B and PFM is on column C). Try on Sheet1!D3 the following formula
=VLOOKUP(A3,Sheet2!B:C,2)
and it will fill in the FPM if a match of Sheet1!A3 is found in Sheet2!B column. You may want further reference
https://support.office.com/en-us/article/vlookup-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1

How to copy selected columns and filter them before hand in excel VBA

I am just a beginner in VBA. I am trying to copy some data from one workbook that is updated daily to a master woorkbook and generate a report. I want it to first filter one of the columns for nonzero values and copy it with three selected columns for example columns T,C,N. I have looked everywhere for an answer but I haven't succeeded yet. Please help.
You can check if a given cell has value 0 by something like this If Sheets(sheetname).Cells(rownumber,columnnumber)=0 Then
You haven't specified what do you want to do on the other workbooks with the cells that were empty.

Excel - Can not compare two spreadsheets

I have gone through V-look-up guides online but I can not find one that explains what I am looking for. I am trying to avoid manual checking.
What I have:
Two sheets, Sheet 1 and Sheet 2. Both sheets have the same column names (A1:G1) with multiple rows.
Sheet 1 contains my spreadsheet where I update daily. Sheet 2 is the same spreadsheet that is imported from a application (but has hourly updates). Data can change in each row (for some columns) along with additional added/deleted rows. The data is text, dates and numbers (mixture of both too).
I want to run a formula to highlight the changes on sheet 1 (grabbing the updates from sheet 2. Once I find out the formula works correctly, I would like to know how to replace the Sheet 2 updates onto my spreadsheet (Sheet 1).
I am looking for a formula outside of creating a macro (worst case scenario).
Currently I have the following vlook up formula:
=VLOOKUP(A1,sheet2!$A:$A,1,FALSE)
When I run this in another column (lets say in H1 in Sheet 1), it will display "N/A" if that column (A1) in Sheet 2 is not the same. If it is the same, it will write out the column name.
When I use the following formula highlighting all the cells in Sheet 1, I get a values error:
=VLOOKUP(A1:G33,Sheet2!$A:$G,1,FALSE)
How could I apply that formula to the whole spreadsheet (I guess it would apply to both sheets) and have it highlight records in my spreadsheet (Sheet1). Could it also highlight rows that are missing or added?
The data in Column 1 and 2 would never change (they are ticket numbers). Only change that can apply is if ticket is closed, so when I import the updated spreadsheet that row isn't there anymore. If you think there might be a better way to tackle this down, I would like to hear.
Please let me know if I am not clear.
Here are some example screenshots:
Just in case, the formula for the totals are (adjusting the columns for each):
=SUBTOTAL(3,INDEX(C:C,2):INDEX(C:C,ROW()-1))
Sheet 2 is setup very similar. When I import it into excel, the columns are the exact same as Sheet 1, the only difference can be more/less rows (along with the updates for each row).
You can use conditional formatting.

complex VBA to remove duplicates from multiple pages and then delete blank rows looping all sheets

I've spent hours on the internet trying to work something out but can not get a vba fix to work on a complex sheet like mine! Your help would be appreciated.
For all these queries I'd like to loop through all sheets, but skip the sheets named "timekeeper code", "bill date" & "summary" - these names will always be the same but I can not name the sheets. The script needs to loop as the names and quantity will vary.
On all other sheets it will loop I need to select the range "A1002:A2003" and if there is a duplicate delete the row.
I also need to do the same for range "A2005:A3006".
Please note that both of these ranges are with in tables but again the table names can't be named as they will vary.
I'm not sure if it helps but the full table range for A1002:A2003 is A1002:B2003
and the full table range for A2005:A3006 is A2005:AD3006
I can also not go from A1002 straight to A3006 as some values will be shown in both ranges but I will need them both
looping the same sheets,
I then need to delete all rows from A1001 upwards to the last used cell where the cell value is = ""
I have a very limited skill on VBA and quite a complex query so I'm basically stuck starting from scratch so any code you have to do this would be amazing!
I hope this makes sense.
Many thnaks
First google entry solves your problem:
Delete all duplicate rows Excel vba
now you have to generate a loop around this function to target the correct sheets.

Duplicated cells skip 10 rows

I have an Excel spreadsheet with two sheets, Sheet 1 contains some text and formulas I wish to duplicate down to write 2,000 odd lines of C# code for my project. Extremely repetitive, so I thought I could use Excel to write it for me. Sheet 2 contains an extract from my database which I wish to use to populate that values with. My section of Excel code looks like this and is spread out over 10 rows and 5 columns:
new AccountingPeriod()
{
MonthCovered="=Sheet2!B2",
StartDate=DateTime.Parse("Sheet2!C2"),
EndDate=DateTime.Parse("Sheet2!D2"),
AccountingPeriodDescription="Sheet2!E2",
Active='=Sheet2!F2',
April='=Sheet2!G2,
TaxYear="Sheet2!H2"
},
When I highlight these 10 rows and use the Excel duplicate tool I want the cell references (for example, in my spreadsheet Sheet1!D3 = Sheet2!B2, I want Sheet1!D13 = Sheet2!B3 NOT Sheet2!B13) to increment by 1, not 10 as it's doing in my spreadsheet.
We have tried an alternative solution of writing a macro to insert 10 blank rows in Sheet2 for every populated row so that the duplicated references are correct in Sheet1 but we're currently failing miserably at getting that to work correctly.
Instead of a direct reference that is going to change on a 1-to-1 with the copy, use the INDEX function with a little maths to achieve the 10-to-1 row stagger.
In Sheet1!D3 this references Sheet2!B2.
=INDEX(Sheet2!B:B,INT(ROW(1:1)/10)+2)
In Sheet1!D13 this references Sheet2!B3.
The OFFSET function can accomplish the same thing but it is a volatile function that recalculates whenever anything in the workbook changes. INDEX provides the same functionality while remaining non-volatile and will only recalculate when something that affects its returned value changes.