I'm struggling to get my Excel spreadsheet (2010) to do what I want, but I'm not sure its possible!
What I have is diagrams with numbers (with the numbers in circles) on sheet two, on sheet one I have VLOOKUPs waiting to input the appropriate data. What I want, is for the user to click on the circle containing whichever number, then for that number to be put in the first column of the sheet, thus causing the VLOOKUP to fill in the rest of the data. Any ideas? I'm trying to play about with macros but I've had no luck so far.
Any help would be greatly appreciated
Jazz
EDIT: I've managed to get a macro to copy and paste the data to the correct column, what I now need is for the macro to put the pasted data into the next blank cell in the column
What if you try a command like the following:
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
After you have unlocked the worksheet and copied the data, have the VB code go to the active sheet, and paste your data in row that follows the last used row in the worksheet. If you can weave something like this in, you will be able to avoid indexing the rows with a number. You will also be able to deal with the case that there are empty rows sprinkled within column A in this case.
Related
I don't understand coding, I've tried but it just doesn't make sense to me. Much respect to all who can learn and understand this complex other language. If any of you can help, I'd be grateful.
I suspect this is a simple problem to solve...
I have a range of cells, A1:E30, in cells in columns B and C within this range data is entered using drop down lists, when certain data is entered into these cells information is automatically entered into columns A and E on the same row. Not all cells within the range will contain data.
What I'd like is a command button that when pressed will copy only the cells within this range that contain text and then paste that text into notepad, without any blank lines and keeping corresponding cells next to each other.
I can do the very basic:
Range("A1:E30").Copy
Shell"notepad.exe",VbNormalFocus
Sendkeys"^V"
The code copies the entire range, but this includes empty lines.
Is there a way to do what I need?
Any help would be most appreciated.
If the lines that are empty are within the data block, you can sort prior to copying. If the blank lines are at the end, you can find the last row of data prior to copying and only copy the data.
LastRow=Cells(Rows.Count,1).End(xlup).Row
Range("A1:E" & LastRow).Copy
I'm using NPOI.
I read in an Excel workbook with two sheets that acts as a "template" for the result workbook I'll be generating. Sheet 0 is empty aside from some header rows and sheet 1 has a number of rows of formulas. The formulas generally refer to the sheet 0 and pull data from it.
I can't write directly into the template workbook because I'd be having to move rows out of the way and it would get ugly fast, so in code I create a new result workbook with two sheets. Based on a preset configuration file, I populate the sheet 0 of this result workbook with data, row by row, cloning the style and formulas of certain rows from the template workbook. Sheet 0 ends up filled with data, and sheet 1 is basically a row of formulas copied and adjusted relatively, typically pulling data from sheet 0 with a small calculation here or there.
All of my data in sheet 0 is text and cannot be interpreted as numeric, dates, etc. So I set my data cell types as String.
In code I then loop through all cells in sheet 1 and EvaluateInCell.
I do this to obviously evaluate the formulas, but also to remove the formulas and leave the copied/calculated results. This is just a requirement of the work I'm doing. We deliver the end results and no formulas.
I save the resulting workbook.
In general things look good, except where I have cell formatting, the formatting seems to not be applied.
The formatting IS there when I get the cell formatting properties in Excel.
For example I might have text data that is a date-time in my data that shows up as:
7/7/2016 9:54:55 AM
this IS what the original data text is, but on my formula sheet I have a custom cell format yyyymmdd.
And yet, the cell still shows: 7/7/2016 9:54:55 AM
In Excel I then do something like manually edit the value, for example delete the last 'M' and retype 'M' and hit enter, that cell changes to the desired format and shows:
20160707
So again, the formatting IS there, it's just not applied.
I don't want to have to manually edit cells, or do anything once the workbook is opened in Excel by my customers. I want the resulting workbook to open up with the values formatted.
I've tried a few things that seemed like a shot in the dark, like:
this.ResultWorkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
((XSSFWorkbook)this.ResultWorkbook).SetForceFormulaRecalculation(true);
But this didn't help.
Any thoughts?
can you try either of this apprioach while setting the formula for cell
Approach 1
ICellStyle dateCellStyle = workbook.CreateCellStyle();
dateCellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("yyyymmdd"); // Or prefix single quote for data when writing it to excel file like 'yyymmdd ex: '20160707
Approach 2
XSSFCellStyle dateCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
XSSFDataFormat dateDataFormat = (XSSFDataFormat)workbook.CreateDataFormat();
dateCellStyle.SetDataFormat(dateDataFormat.GetFormat("yyyymmdd"));
I ended up looking at the template Excel file's cell I'm writing into. It looks like if it's not DateUtil.IsCellDateFormatted and the cellStyle.DataFormat is not 0x31 (text based on BuiltInFormats), then it must be numeric.
Based on that I try to convert my text to DateTime or double as applicable, and call SetCellValue with those converted variables. Otherwise I write the text.
This seems to be working for cases I've encountered.
I am pretty new to excel and finding it a little tricky so any help would be appreciated!
I have a master sheet where data is going to be input by people. From this master sheet I have used IF statements to copy relevant columns to another sheet in the workbook. (not sure if thats the best way).
So when a new data row is input into the master sheet, this creates a new row in the other sheet because its displaying what has been input in the master. This is building up a sub-table so to speak. From this sub data (whether turned to a table or not) I want to create pivot tables.
Issues:
If the sub data is turned into a table, when new data is input in the master sheet the sub-table does not expand.
Trying it another way, without creating a table with the sub data I tried to create a dynamic range using OFFSET. However when an entry is deleted from the master sheet this creates a blank row in the dynamic range that is being used to create the pivot table.
Any help would be much appreciated! I've looked into OFFSET, MATCH, VLOOKUP and it's a little confusing although I do get the gist of what these functions can achieve.
Thanks in advance!
This particular combo is used to fiddle around with ranges, for example validations and complex lookups.
They will not help you with your issue.
The range expansion is triggered when new data is entered into an adjacent cell, not when its existing condition becomes recognizable.
The =OFFSET() is used to fiddle around with ranges.
The MATCH(...,0) finds the first match of your string, in your case the lack of string.
If you could in fact set up a Pivot table to indirect references this formula would be your solution:
=OFFSET(YourSheet!$A$1,0,0,MATCH("",YourSheet!$A:$A,0)-1,MATCH("",YourSheet!$1:$1,0)-1)
where A1 of YourSheet contains somthing like
=IF(IncrementalDataSheet!A1<>"",IncrementalDataSheet!A1,"")
I think I understand the problem you're having. If you have data in A:Z in Sheet1 and you only want to see columns A, T, and Y for example on your more visually appealing Sheet2, then the initial thought would be to put =Sheet1!A1 into A1 on Sheet2, =Sheet1!T1 into B1, and =Sheet1!Y1 into C1. Copy the range down as far as needed to display the data from Sheet1 and Bingo! A nice tidy summarized version.
But wait... If you delete a row from Sheet1, the referenced cell in Sheet2 now just displays #REF!... boo... that's no good.
So, instead of using direct cell references, you can make use of the INDIRECT function to make sure the values produced are always relative based on the address of the target cell.
In Sheet2 you would put:
A1 =INDIRECT("Sheet1!"&(CELL("address",A1)))
B1 =INDIRECT("Sheet1!"&(CELL("address",T1)))
C1 =INDIRECT("Sheet1!"&(CELL("address",Y1)))
And copy down. At first glance it looks just like the original result, the difference is you can now delete rows from Sheet1 without hurting the output on Sheet2 because the indirect references will just look up new values from where everything shifted.
You should then be able to pivot off of the result dataset pretty easily.
That said... when you make a pivot table you pick which columns you include, so you could just pivot off of the original giant table and exclude any columns that you're not interested in summarizing.
i have a specific problem to solve. I dont know how to do it but want to do it without macro or worse without VB script.
I will explain what i have and then what i want to do.
I have (plan to have) many sheets in worksheet. first sheet is some intro sheet, where i have also one column containing name of sheets in every cell. i am using formula "=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)" so i can change name of sheet and it will change also name of sheet in intro sheet cell.
so for imagination i have column N and there i have sheet1, under that sheet2 and so on...
Each of sheets have the same construction and same formulas on the same place, so i have each sheet for every goods.
And now what i would like to have. I want to add a formula into intro sheet where i would summarize SUM (add) or something like that. It would take every value form each sheet on the same place on each sheet. so the formula would look something like this: "=sheet1!C4 + sheet2!C4 + sheet3!C4 + .... + 'any sheet'!C4" but i dont know how many sheets i will have and the number will sometimes change and i dont want to edit formula because i plan to have more this kind of dynamic formulas.
i will just add another sheet into column N and every formula using this excel type for cycle would take and recount formula using this dynamic array. i hope you understand what i want. my problem is much more complicated but when i describe it more into detials you would loose the point of my interest.
thanks for any suggestions
edit: but if there is only a solution using VBA script, i will have to use it. i dont want to change formula everytime i add another sheet into worksheet
What you describe is a 3D formula. You can do something like
=SUM(Sheet1:Sheet4!A1)
Excel will sum cell A1 in all sheets from Sheet1 to Sheet4 and any sheets that are between these two. You can insert new sheets and they don't have to be named SheetX.
In order to manage the 3D formulas more efficiently, you could use two sheets like bookends before and after the sheets you want to include in the formula: Insert two sheets called "First" and "Last" and ensure that all sheets you want to sum are arranged between these two sheets. Then on your intro sheet use
=SUM(First:Last!A1)
You can hide the "First" and "Last" sheets and only unhide them when you need to check your sheet arrangements for your formulas.
You can insert new sheets and make sure that they are located between your bookend sheets. Drag sheets in and out between the bookends to include or exclude them from the 3D formula.
I've got a spreadsheet containing several sheets and want to put all values from column A from each sheet into a single column on another sheet.
Is this possible?
Alternatively is there an easy way to "flatten" the data for export (each sheet has the same column structure)?
If I were you I would open up the macro recorder and then record your manual actions in doing what you want in VBA. The code will be quite simple to understand and then you will be able to edit it as you wish. VBA macros are ideal for this type of mundane data manipulation within a spreadsheet.
I think you need the VLOOKUP function, but I'm not clear on exactly what you want to do; do you want the new column to contain all the values from column A of sheet 1 followed by all the values from column A of sheet 2, then all values from column A of sheet 3 and so on, or do you want the new sheet to contain the sum (or means, or concatenation) of each of the column As from several other sheets?
You can put this command on the sheet where you want to paste all columns
=CONCATENATE(Sheet1!A1,Sheet2!A1)
The above command is only for extract data from two sheets, however you can add more i.e. Sheet3!A1....