I have a blank Excel table saved as a template into which I copy data from the clipboard (originating from a website).
Is there a way using VBA to auto-adjust the width of each column to its content after the data (text) has been pasted in ?
Edit: The data I paste will always be inserted starting from A1 and will always fill the same number of columns.
You can do it with AutoFit:
Columns("A:B").EntireColumn.AutoFit
You can perform the following:
Columns("A").Autofit
You can do it with a worksheet change event, but if your worksheet is changed in any way after the paste, it runs again. Not an issue unless you're trying to hide columns to focus on a subset of data because they will autofit themselves constantly.
I recommend using a button to paste the data and including the column width setting as part of the paste command.
Related
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 have data in one workbook and I have filtered columns in another workbook, when I want to copy the data from one workbook and paste it to the visible cells in the filtered area, it gets pasted to the hidden cells as well.
I googled alot but nothing was useful even I tried the Kutools software but did not work.
How to paste the data into visible cells?
A workaround I like to use is to use reference in the filtered sheet. Slightly longer method, but it works. Follow the steps below
Set the reference in first cell. E.g. ='Sheet1!A1'
Click and drag to copy the formula to all cells below (or Copy, and Paste into multiple selection). DO NOT double click to fill down, as it will include hidden cells.
If needed, clear filter and copy- paste values
Let me know if this works for you.
I created a series of cells with icon set. How can copy the last cell to another sheet including the icon set it currently have?. When i copied the last cell to another sheet, it does not preserve the same icon set.
With an in-built formula it can't be done without using something like VBA as well.
I copied data from a callmanager. i want to use the data it displays in the spreadsheet which is hh:mm:ss. But in the input box in the top it shows other data (date and time which i think display the date and time of recording of the data). When I try to use to manipulate the hh:mm:ss in the spreadsheet it keeps using the data in te input box. How can I tell excel to use the data displayed in the spread sheet and remove the data in the input box?
thanks in advance!
I don't know of a specific method to do it in excel only, but what I've been using so far for instances like this is:
Copy the column having those values and paste into notepad,
Insert a new column in the worksheet and format it as Text,
Copy everything from the notepad and paste into that new column.
This might be a little awkward, but it works for me ^_^
We are automating Excel using VB.Net, and trying to place multiple lines of text on an Excel worksheet that we can set to not print. Between these we would have printable reports.
We can do this if we add textbox objects, and set the print object setting to false. (If you have another way, please direct me)
The code to add a textbox is:
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 145.5, 227.25, 304.5, 21#)
but the positioning is in points. We need a way to place it over a specific cell, and size it with the cell. How can we find out where to put it when we just know which cell to put it over?
If you have the cell name or position, you can do:
With ActiveSheet
.Shapes.AddTextbox msoTextOrientationHorizontal, .Cells(3,2).Left, .Cells(3,2).Top, .Cells(3,2).Width, .Cells(3,2).Height
End With
This will add a textbox over cell B3. When B3 is resized, the textbox is also.
When you copy & paste a textbox, Excel will place the new textbox over whichever cell is currently selected. So you can achieve this very easily by simply using the VBA copy & paste commands. This can be particularly useful if you are going to be using a lot of very similar textboxes, as you are effectively creating a textbox template.