I want to open and process a number of Excel files using Matlab. The task is to copy and paste an area to a new sheet in a new Excel workbook. The area is defined by a contiguous selection of rows (e.g. rows 1 to 3) but a possibly non-contiguous selection of columns (e.g. columns 1 and 3). A requirement is that the copying-and-pasting operation should preserve comments.
The requirement that comments are to be preserved led me to the use of ActiveX as opposed to xlsread and xlswrite. I am able to open, select and paste a contiguous selection to a new file and save that file but I fail to make the selection non-contiguous.
The following lines are key:
DataRange ='A1:C3'; % Select contiguous selection.
Sheet1.Range(DataRange).Copy; % Select the columns to copy.
Sheet2.Range('A1').PasteSpecial(13); % Paste, including comments.
All is well so far and the code behaves as intended.
I then try to modify the code to cope with non-contiguous columns as follows:
DataRange = 'A1:A3, C1:C3'; % Only select first and third columns.
Matlab returns with an opaque error message (Object returned error code 0x800A03EC) rather than reaching the intended outcome where the contents of rows 1 to 3 and columns A and C are selected and copied.
Unfortunately my VBA skills are non-existent and I do not know how to proceed. I would appreciate if someone could point me in the right direction using this simple example.
Related
I have a userform created using Excel VBA that is used to register information before saving it to a worksheet. All the information the user enters is stored in a listbox and then copied to a worksheet. However, I need to copy each column of information to different ranges in the worksheet, they are not all together to copy whole listbox with the simple .List or .Value properties.
The listbox has four columns. Right now I am trying to get all the values stored on the second column to copy them to the worksheet. The number of rows in the listbox constantly changes depending on how many entries the user registers. I tried the following piece of code:
Range(FirstColumnRange).Resize(lstAllProducts.ListCount, 1).Value = lstAllProducts.List
This works perfectly for getting all the information on the first column of the listbox. Although the .List property gets all the values on the listbox, using the .Resize property with a fixed column value of 1 just saves the first column to the worksheet ignoring the others. The issue is that I can't seem to do the same for the other columns.
I tried the following code for getting the values of the second column:
Range(SecondColumnRange).Resize(lstAllProducts.ListCount, 1).Value = lstAllProducts.List(lstAllProducts.ListIndex, 1)
However, this only works if a row of the listbox is selected, and only saves that value. Is there a way to modify that last part of that code (lstAllProducts.List(lstAllProducts.ListIndex, 1)) so that I can get all the values on the relevant column (second column in this case) without selecting anything in the listbox? I would really appreciate any suggestion. Also, I would prefer a solution that does not require looping like the one I used for the first column.
I have a large file with a Scenario Manager, where changing a single cell on the Summary worksheet changes the visible scenario throughout the rest of the workbook. Data Tables are working a treat providing the headline values for each option.
I'd like to have a drop down on each sheet that when changed will change the same single cell on the Summary worksheet, so I don't need to go back to the Summary sheet every time I want to switch visible scenarios.
This is a simple process if I'm using macros and would be the solution I'd normally jump straight to. But this needs to be done without macros and this is where I'm now struggling.
Does anyone know if this is possible (without macros) and point me in the right direction?
Josh
You can insert combo box (Developer Tab > Insert > Form Controls > Combo Box) on each sheet. Mention linked cell as a cell of the summary sheet (Absolute reference with sheet name). That cell will give you index of the item selected in the drop down list. Then you can insert index formula in the cell you want to change every time to get value of the drop down list. Once you insert it on one sheet you can copy it to other sheets. No macros required.
I would like to set a value for the default size of the OLE object when I copy and paste a range of cells into autocad from excel.
Normally, when I copy and paste from excel into autocad, in autocad, i have to mess with the scaling to get it just right. This takes unnecessary time.
Instead, I want excel to paste this range of cells at a certain height and width. I'm curious if there are properties in excel or autocad where I can set the default x and y dimensions of the copied object.
The range of cells to be copied in excel are always the same, but it just will have different data in it each job.
You can't do that on-the-fly unless you made yourself a sophisticated lisp.
For me I do all the adjustments I need on one ole object only (either scaling or aligning it to a line or a rectangle). I copy this object multiple times in the drawing then I edit these copies (OLE > OPEN) by copying the ranges I need from Excel into them.
I have two spreadsheets, one of them is a list of events taking place this year and one is a calendar that has a row for all 365 days per year.
I had put the event names in to the calendar and then filtered that sheet so that only rows with event titles entered are visible using the dropdown on the header row.
I now want to copy and paste the rest of the event information over in batch without having to do it line by line and so selected the appropriate column and used Find & Select-> Go to Special...->Selected Visible Cells only but when I then try to paste to those visible cells I get the error message:
"You can't paste this here because the Copy area and paste area aren't the same size. Select just one cell in the paste area or an area that's the same size, and try pasting again."
I've checked that I'm copying 230 rows and I've selected 230 rows, I've even tried resizing the cells so they're the same dimensions but I just get the same error every time. If I only select one cell then it pastes the data in to the invisible cells as well.
I've tried googling the error message but not found a solution that works so any help will be much appreictaed.
Actually found the VBA code I need to do this here: https://www.extendoffice.com/documents/excel/2617-excel-paste-to-visible-filtered-cells.html
I am new to Sikuli. I need to copy data from excel sheets and paste them to a DB query using sikuli script. And how can I iterate among the excel cells to copy and paste the data repeatedly.
These data needs to copied and pasted one after the other.
It might be easier to copy all of the cells at once, then paste them one by one.
once Sikuli has opened Excel, you could do something like:
type(Key.HOME, KeyModifier.CTRL) #takes you to cell A1
type("a", KeyModifier.CTRL) #select all
type("c", KeyModifier.CTRL) #copy to clipboard
fromExcel = Env.GetClipboard().strip() #get clipboard contents into Sikuli, without leading or trailing white space
cells = fromExcel.split("/n") #split each cell into list on newline
#go to the destination app, maybe using App.open("nameOfYourApp") if it's not open yet, or App.focus("nameOfYourApp") if it is already open
for cell in cells: #use python to iterate through your list
#navigate to the line or cell where you want to paste
paste(cell)
Would something like that be of help?
Rather than providing a specific approach let's understand the options you have.
Simulate user keyboard actions (like it is described here by #autoKarma).
Excel sheet having a very specific structure allows you to detect some key points like first column and first row and then calculate other cells locations based on them.
You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. If you only need to read the document and to to amend it, I believe this will be fairly easy to do.
Note: In all cases you will obviously have to think of how do you bring yourself to the point where you have an open Excel sheet on your screen and how to dispose of it when done.