So I am populating a spreadsheet with a copy n paste of my banking transactions. I want excel to populate a cell 10 to the left of it with that specific costs cost centre number.
Eg, Petrol has a cost centre number of 10
I copy and paste my bank statement in, the sheet sees all the cells containing 'petrol' and populates the cell ten to the left with a 10
I do not want to do this with a formula, I want to put it in vba.
Can someone help please?
Thanks in advance
You can use the following code to copy a value ten cells to the left.
Cells(Row,Column).Value = Cells(Row,Column + 10).Value
To get the values for 'Row' and 'Column', you can use the find function to find the address for 'petrol' and all the other values that you want.
I apologize for being newbie as I am having difficulty with this concept. I really don't know where to start.
I just need a code in Sheet2 using an 'Update Button' to do the following:
In sheet1, this information will come from different Team Leaders as duplicate or even triplicate records shown in example 'Seat no. 1.2' can occur.
In sheet2, under 'Seat No.', this is constant and will never change (serves as my reference for my other Pivot and lookup codes)
In sheet2 columns, under 'User 1', the code will paste the 1st value detected; Under 'User2', the code will paste the 2nd value detected; Under unassign, the code will paste the 3rd value detected
In sheet2 column under Status, it will show Solo if only 1user, 'Sharing' if there are 2 users and 'Vacant' if no user.
Note: only two users are allowed for every Seat No.
Hope you can help me. Thank you so much
You don't need to use macro for this. In user 1 column use this:
=IF(ISERROR(VLOOKUP(Sheet2!A2,Sheet1!$A$2:$B$50,2,0)),"",VLOOKUP(Sheet2!A2,Sheet1!$A$2:$B$50,2,0)),
where 50 replace with number of your rows.
In user 2 use this:
=IF(SUMIF(Sheet1!$A$2:$A$50,Sheet2!A2)>1,IF(ISERROR(VLOOKUP(Sheet2!A2,OFFSET(Sheet1!$A$2,MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),0,50-MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),2),2,0)),"",VLOOKUP(Sheet2!A2,OFFSET(Sheet1!$A$2,MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),0,7-MATCH(Sheet2!A2,Sheet1!$A$2:$A$50,0),2),2,0)),"")
and again replace 50 with number of your rows.
In status column, use IF with SUMIF.
And in Unassign column, use vlookup like in first column, but from down to up. There is lot of articles about it. Dont forget to use if in start, which will check if there is 3 IDs for seat.
This doesn't need VBA unless you insist to do so:
User1 column:
=IFERROR(IF(VLOOKUP(A2,Sheet1!$A$2:$B$9,2,0)=0,"",VLOOKUP(A2,Sheet1!$A$2:$B$9,2,0)),"")
User2 column (array formula, press Ctrl + Shift + Enter keys simultaneously):
=IFERROR(INDEX(Sheet1!$B$2:$B$9,SMALL(IF($A2=Sheet1!$A$2:$A$9,ROW(Sheet1!$A$2:$A$9)-ROW($A$2)+1),2)),"")
Status column:
=IF(COUNT(B2:C2)=0,"Vacant",IF(COUNT(B2:C2)=1,"Solo","Sharing"))
Unassign column (array formula, press Ctrl + Shift + Enter keys simultaneously):
=IFERROR(INDEX(Sheet1!$B$2:$B$9,SMALL(IF($A2=Sheet1!$A$2:$A$9,ROW(Sheet1!$A$2:$A$9)-ROW($A$2)+1),3)),"")
Hope this helps.
I am looking for a way to dynamically pivot data in an Excel sheet to put the data in a universal format no matter how wide the data set is.
For example: I want to be able to take a spreadsheet that could have 5 columns, 30 columns, or x number of columns to make it pivot to a universal format that is only three columns wide.
Here is a sample of how the original data could look:
I want it to look like this:
Is there a way to do it, either by macro or using any other Excel functions?
Assumes labels/data is in Sheet1 starting A1.
Insert a new ColumnA.
For Excel 2003: Activate any cell in your summary table and choose Data - PivotTable and PivotChart Report:
For later versions access the Wizard with Alt+D, P:
Select Multiple consolidation ranges and PivotTable and click Next >.
In “Step 2a of 3”, choose I will create the page fields and click Next >.
In “Step 2b of 3” (not shown in the modal!) specify your summary table range in the Range: field (A2:E6 for the sample data) and click Add, then Next >.
In “Step 3 of 3”, select a location for the PivotTable (the existing sheet should serve, as the PT is only required temporarily):
Click Finish to create the PivotTable:
Drill down (ie double-click) on the intersect of the Grand Totals (here Cell L4 or 16):
The PT may now be deleted.
In A2 of Table:
="Summary"&RIGHT(B2)
Convert the resulting Table into a conventional array of cells by selecting Table in the Quick Menu (right-click in the Table) and Convert to Range.
In a spare column starting in Row2 series fill integers down, from 1 to however many rows of data you started with (4, in the example). Then series fill that series to suit.
Sort sheet by that (spare) column, Smallest to Largest, with My data has headers checked.
Delete Row1 and spare column and hopefully you will end up with:
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.
I want to find the average of every 100 rows consecutively in 2 million rows and save these 2000 values in a new column.
Can any one help me either by a VBA or by a Formula in Excel 2007.
waiting for the reply.
The trick here is to set-it up correctly. With the proper set-up, this is a cinch, really. VBA is just going to make this a wee bit easier, but native formulas can do just as well.
Assume I have values in A1:A1000. A1 has 1, A2 has 2, etc. You get the point. Eventually, A1000 has 1000.
Now, copy the following set-up for the specified cells:
B1: 1
C1: 100
B2: =C1+1
C2: =C1+100
Drag down to B10:C10.
Now, input the following formula to D1:
=AVERAGE(INDIRECT("A"&B1&":A"&C1))
Drag down to D10. Voila. You have the average of each 100-row cluster.
Screenshot:
Let us know if this helps.
A single formula:
=INT((ROW()-2)/100)
in say B2 and copied down (to group in hundreds) and a PivotTable with the ColumnB label as Row Labels and Average of the value label in Σ Values is quite straightforward.
If the banding is required, change the formula for =ROW()-1 and Group in the PT.