I am having trouble copying and pasting the hyperlinks from one sheet to another using VB.
I am using a database connection to pull the hyperlinks into Sheet1 and then using a macro to copy and paste the database data into another sheet, however the copy and pasting doesnt paste the "Clickable" link, only plain text.
How do I go about copying a hyperlink using VB, is this even possible??
Sheets("Sheet1").Select
Range("J19:K100").Select
Application.CutCopyMode = False
**Selection.SpecialCells(xlCellTypeVisible).Copy**
Sheets("Sheet2").Select
Range("C5:D100").Select
ActiveSheet.Paste **Link:=True**
Any help is much appreciated!
Thanks!
UPDATE
I am using a database connection, which holds the URL/Hyperlinks. I have tried your code for filtered table, however this only works if the links are directly input into the cell. i.e entered through right click on cell > Hyperlink.
Has anyone achieved copying URL's from a database connection in excel before?
Thanks.
You can use following paste special option to paste links.
ActiveSheet.PasteSpecial xlPasteAll
Related
I am trying to copy a row of data from one sheet to another having run some other macros, however I keep getting the error message that the paste area and copy area are not the same size and shape.
I have tried using special cells paste method but it seems be missing the data from the last 9 columns.
Code:
id.EntireRow.SpecialCells(xlCellTypeConstants).Copy
missingdata.Range("A" & Rows.Count).End(xlUp).Offset(1,1).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
I need help changing the code so it copies the full row of data and pastes it under existing entries in missingdata.
It seems when it works when I choose to paste in Column A, however it does not allow me to paste from column B
I normally use:
Rows(index).Copy
Cells(1,Rows.Count+1).Select
ActiveSheet.Paste
I want to do the equivalent of selecting a cell in a sheet, pressing F2 and then CTRL+V, so that all the formatting such as bullets, bold characters and breaklines are preserved and pasted into one cell. Please note that I'm NOT copying from excel sheets, rather im using excel vba to copy from a Word Document.
I've tried:
Sheets(1).Cells(1,1).Select
SendKeys "{F2}", True
SendKeys "v", True
Application.Wait(Now + TimeValue("0:00:5"))
Sheets(1).Cells(1,2).Select
But the above code pastes in the cell(1,2) of the active sheet instead of (1,1).
Please suggest an alternative method for this.
To copy and paste a cell "preserving the formatting" (ie bold, underlines, text column, newlines, special characters (like bullet points) etc. You could use record macro to create code like the following which is simple copy, paste. You do not need to press F2 (as this will only give you access to the raw value - not the formatting):
Range("C3").Select
Selection.Copy
Range("D6").Select
ActiveSheet.Paste
modifying this example for you needs:
With Sheets(1)
.Cells(1, 1).Copy
.Cells(1, 2).Select
.Paste
end with
SendKeys "^v", True
This will send Ctrl+v. You shouldn't need the Wait command because the {True} argument for {SendKeys} tells Excel to wait until it's done before returning continuing with the macro. I'm not sure if there's a better way to do this that doesn't involve SendKeys, unless you want to paste into multiple cells and then combine them.
I'm trying to build a macro that looks like this:
Sub CopyAsValues()
Selection.PasteSpecial xlPasteValues
End Sub
It seems to me that Excel requires from me to add a copy line, e.g.:
Range("C1:C5").Copy"
But I don't want to. I want to manually copy from cells, and then use the macro to paste as values. How can I do that?
You do not need macro for this, comfortable way to paste only values, I guess, will be using quick access toolbar as in picture below
Excel Option ~~> Customize ~~> Choose commands from [All Commands] ~~> Select "Paste Values" command and add to toolbar
so you will receive button in top of the excel window with required option
then you can copy and paste only values using this button
Well first of all I found couple of answers while googling but most of the forums are blocked in my Office Network hence asking this question here! One more intention is to get an answer in plain English :P
I understand if we set Application.CutCopyMode = False then the Copied/Cut results will be vanished (i.e. memory will be cleared) but when should we use this and when not to use this? Can anyone please help?
By referring this(http://www.excelforum.com/excel-programming-vba-macros/867665-application-cutcopymode-false.html) link the answer is as below:
Application.CutCopyMode=False is seen in macro recorder-generated code when you do a copy/cut cells and paste . The macro recorder does the copy/cut and paste in separate statements and uses the clipboard as an intermediate buffer. I think Application.CutCopyMode = False clears the clipboard. Without that line you will get the warning 'There is a large amount of information on the Clipboard....' when you close the workbook with a large amount of data on the clipboard.
With optimised VBA code you can usually do the copy/cut and paste operations in one statement, so the clipboard isn't used and Application.CutCopyMode = False isn't needed and you won't get the warning.
Normally, When you copy a cell you will find the below statement written down in the status bar (in the bottom of your sheet)
"Select destination and Press Enter or Choose Paste"
Then you press whether Enter or choose paste to paste the value of the cell.
If you didn't press Esc afterwards you will be able to paste the value of the cell several times
Application.CutCopyMode = False does the same like the Esc button, if you removed it from your code you will find that you are able to paste the cell value several times again.
And if you closed the Excel without pressing Esc
you will get the warning 'There is a large amount of information on the Clipboard....'
There is a good explanation at
https://stackoverflow.com/a/33833319/903783
The values expected seem to be xlCopy and xlCut according to xlCutCopyMode enumeration (https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/xlcutcopymode-enumeration-excel), but the 0 value (this is what False equals to in VBA) seems to be useful to clear Excel data put on the Clipboard.
Is there a way to use the pastspecial method to paste a copyied chart as a bitmap to another worksheet. Currently this is my syntax-
PasteSheet.PasteSpecial (Format:="Bitmap", Link:=False, DisplayAsIcon:=False)
Where PasteSheet is the other worksheet i want to paste to. Currently with this code, it is only pasting in the active sheet. Do i have to use select to copy then select the page i want to paste to, then change back to the sheet I copied from? I hope not as I have a lot of sheets haha.
Thank you
Edit: I have found out that if I Copy the chart as a shape rather than a chartobject I can use the pasteSpecial method to paste to another sheet. That being said it now pastes charts into one another creating one mega chart haha.
GraphSheet.Shapes(chtName).Copy
PasteSheet.PasteSpecial Format:="Microsoft Office Drawing Object", Link:=False , _
DisplayAsIcon:=False
This will work without needing to activate/select Sheet2:
Sheet1.ChartObjects(1).Chart.CopyPicture
Sheet2.Paste
Do i have to use select to copy then select the page i want to paste
to, then change back to the sheet I copied from?
Yes - the sheet you paste into must be active. Use Sheets("mytargetname").Select - just using Activate isn't enough...
If you set
Application.ScreenUpdating = False
your screen won't flash while you do this...