excel vba: Specific data columns moving to the right - vba

I am having trouble with writing a small code of VBA that does the following: In a huge dataset, search a particular column for entries that are obviously wrong (e.g. being above 50,when they should be from 1-10).I want this to find these entries,and copy alla the columns to the right of it and move them 3 columns further to the right.It is some sort of data cleaning.Thanks

Not sure why you would need VBA. Lets say that column A should be populated with numbers between 1 and 10. And columns B,C and D are populated with other data.
Select cell E1 and put in the formula =IF($A1>50,A1,"") in the formula box and push CTRL + Enter.
Use the drag handle to copy the formula into cells F1, G1, and H1.
With cells E1 through H1 selected, double click on the drag handle of cell H1.

Related

Excel VBA: Auto-sum the value of three cells and insert into the fourth cell

I have four columns A, B, C, D. The values of the cells start from A1,B1,C1,D1 and user may go up till A100,B100,C100,D100 (on click of a add button, after inserting values in each rows, one at a time)
When user will enter any value in A1 or B1 or C1, it should sum up and the value need to reflect in D1. There may be scenario like user may enter only values in one of the cell and leave other as it is. like A1 as blank, B1 as blank and C1 as 100. So in D1 it should reflect 100.
Just to mention, this is a protected sheet with a lot of different features, like cell level validation, sheet level validation, and the entire sheet will be locked other then one row where user will be able to enter the details and then he will click on ADD button, on click of this button, first all the fields will get validated and if successful then only a new row will be added.
Please help..
This doesn't require any VBA code. Just enter following formula in D1 cell: =A1+B1+C1 and drag it all the way down until 100th row. This way, blank cells are treated as 0.
So, if cells in A,B,C columns are blank, correspnding value in D column will be 0.
Also, value in D column would be raclculated on every change in column A,B,C in corresponding row.

Excel: How to let formulas change relative to each new group of formula groups?

I am having an issue in Excel dragging to fill in formulas. I have formulas in rows such that each row has a different formula which reference to rows/cells on other sheets.
Let's say on Sheet 1, the formulas in the cells C2:C9 pulls data from Sheet 2 from cells C4, G4, H4, etc. If I highlight Sheet 1 cells C2:C9 and then click to drag down to form another group of formulas in cells C10:C17, the formulas inside change their reference by 8 rows such that if Sheet 1 C2 pulls data from Sheet 2 G4, the next similar formula in Sheet 1 C10 ends up pulling data from Sheet 2 G12.
This is the problem I am having; instead of the formulas changing to reference every 8 rows, how could I make it so that it only changes by 1 row instead? Or, for every new group of formulas dragged and filled, change the references in those formulas only by 1 row. If there is still confusion, consider if the cells C2:C9 were merged as a single cell. Even if you dragged that formula down, the formula inside would still change by 8 rows despite only forming 1 cell each time.
As far as I am aware, there is no built-in Excel function to do this and I believe the only way to do this would be some VBA code, but I am unfamiliar with VBA language. Since this would be a one time thing, the VBA code could either apply this 'row formatting' as I click and drag, or the VBA code could just automatically fill in the cells for me.
Use INDEX() and some math:
In C2 it would be something like:
=INDEX(Sheet2!C:C,(ROW(1:1)-1)/8+4)
Where 8 is the spacing of the formula and 4 is the first row desired to return.
C2 would return Sheet2!C4, C10 would be Sheet2!C5
Using this you can modify the other formulas to return the desired pattern.

Shift Cells left whle filtering in ms excel 2007

I have a table and i filtered data based on one specific criteria and i want to shift cells left after deleting one selected column data.
Please help.
hey simply use = sign in require left cell and put column position which you want to put e.g if you have data in B1 cell & u want to put the data in A1(left) then simply write =B1 in A1 cell
and drag down upto where you want the data

Splitting data into two columns

I have a very large Excel spreadsheet that looks like this:
However, I want to move every cell in the second column that starts with Location to the next column.
So it would look like this:
No need of VBA
Enter this formula in C2 and copy till last record
=IF(LEFT(B3,9)="Location:",B3,"")
Then copy paste values in column C, filter column B for Location:* and clear the resulting cells in column B or delete the rows (do as needed).
I would copy column B, paste it in column C then select C1 and press ctrl-- (CTRL and Minus together)
Select shift cells up and click OK.
Then either sort by column A or filter out any with a blank in column A.
You can also use this:
=IF(ISNUMBER(SEARCH("Location",B2)),B2,"")
Then apply conditional formatting to your data range as following:
Final Result

How to display a value of a cell using the LARGE formula feature

In Excel using the LARGE function I have listed the top five values in the range of cells C2:C13 into the cells F2,F3,F4,F5,F6. I used the following formulas in the corresponding cells to do so:
Cell F2 I used this =LARGE(C2:C13,1)
Cell F3 I used this =LARGE(C2:C13,2)
Cell F4 I used this =LARGE(C2:C13,3)
Cell F5 I used this =LARGE(C2:C13,4)
Cell F6 I used this =LARGE(C2:C13,5)
Here is a screenshot:
However, what I would like to do is to display the value of the cells to the left of the five greatest values. Below is a screenshot of how I would like it to work if possible:
Please try:
=INDEX(B:B,MATCH(LARGE(C$2:C$13,E2),C:C,0))
in F2 and copy down.
If purely for display purposes you might filter ColumnsB & C an apply a "Top 10..." selection for 5 items.
We could 'cheat' and manage without INDEX in the example provided but, for wider applicability, having chosen the top five values in ColumnF these are then MATCHed to their row numbers in ColumnC and the corresponding row number fed in to the INDEX function to determine the B value.
The following is tested in Google Spreadsheets.
This would be a simple solution:
=MATCH(LARGE($C$2:$C$13,1),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,2),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,3),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,4),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,5),$C$2:$C$13)
Another more precise way:
=LOOKUP(LARGE($C$2:$C$13,1),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,2),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,3),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,4),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,5),$C$2:$C$13,$B$2:$B$13)