Macro to copy values only from one sheet to another - vba

I've this VBA code
Sheets("log").Range("A125:f1000").Copy _
Sheets("data").Cells(Rows.Count, "A").End(xlUp).Offset(1)
and it copies perfectly from sheet log to data. The only problem I'm facing is that it copies formulas with it as well whereas I only want values. I want to use same VBA code with some modifications to paste values only.

Without using clipboard:
Sheets("data").Cells(Rows.Count, "A").End(xlUp).Offset(1).Value = Sheets("log").Range("A125:f1000").Value

Need to add PasteSpecial Paste:=xlPasteValues
Next time try Recording a macro and modifying the code
Sheets("log").Range("A125:f1000").Copy
Sheets("data").Cells(Rows.Count, "A").End(xlUp).Offset(1). _
PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Related

vba code to copy worksheets and paste as values to a new workbook

I'm not very good at vba so excuse my amateur question.
I have an active workbook open containing 3 tabs. I want to build a macro that opens up another workbook and pastespecial values the data from my three tabs into the three tabs on the second workbook.
This is my coding which keeps breaking on the paste special line.
Sub NewVersion_Click()
Dim y As Workbook
ThisWorkbook.Sheets("Fact Find").Range("A5:I283").Copy
Set y = Workbooks.Open("location")
y.Worksheets("Fact Find").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'ThisWorkbook.Sheets("Entity Fact Find").Range("A4:F237").Copy
'y.Worksheets("Entity Fact Find").Range("A4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'ThisWorkbook.Sheets("Suitability Assessment Form").Range("A4:E108").Copy
'y.Worksheets("Suitability Assessment Form").Range("A4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.Close
End Sub
Any help will be really appreciated.
Thanks
Arvin
Here is your paste special for worksheet fact find.
Modify the code to copy the other sheets, but no need to open the file again.
Which file are you trying to close?
Set wb = ThisWorkbook
wb.Sheets("Fact Find").Range("A5:I283").Copy
Workbooks.Open ("location")
Workbooks("location").Worksheets("Fact Find").Range("A1").PasteSpecial xlPasteValues
wb.Sheets("Entity Fact Find").Range("A4:F237").Copy
Workbooks("location").Worksheets("Entity Fact Find").Range("A1").PasteSpecial xlPasteValues

VBA Copy Paste Special

I am trying to copy a range of cells from Sheet "Stream" to the Sheet "General".
Somehow my paste function is not working. Any hint?
Stream.Range("F103:J103").Copy General.Cells(General.Range("F2:J2").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=_False, Transpose:=False)
Sheets("Stream").Range("F103:J103").Copy
Sheets("General").Range("F2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
For value pasting, you need to first copy the range and then paste to destination.
Also you have to use Sheets() to identify different sheets.

Excel Macro is only copying "false" value of a logic statement

I used the Macro Recorder to create a macro to copy files from one worksheet to a second worksheet and reset a form to default values.
When the macro is run the "false" value ("NO") of a logic statement is copied regardless of the value in the cell at the time the macro is run. If I change the value in the false statement from "NO" to any other value (i.e. "Blue") it copies over the new value ("Blue").
Here is the formula for the logic statement:
=IF(AND(D15>VLOOKUP(C13,CCT,3,FALSE),D15<VLOOKUP(C13,CCT,4,TRUE)),"YES","NO")
where CCT is a list.
Here is the code for the macro:
Range("D17").Select
Selection.Copy
Sheets("Worksheet2").Select
Range("G3").Select
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Worksheet1").Select
You might try Worksheet.Activate after you select different sheets. Worksheet.Calculate might be in order as well.
I think that using Range... implies Activesheet.Range. Hope it helps

VBA Copy Paste is Removing Borders

I'm copying and pasting values from one workbook to another using VBA code. However, when I paste, the borders in the destination worksheet are being deleted. How can I maintain the borders when pasting?
Below is my code:
With wsSource
.Range(.Range("A2"), .Range("C2").End(xlDown)).Copy wsDestination.Range("A3")
End With
I have read that the PasteSpecial method could be of use, but I don't know how to implement it in the above code.
Thanks!
Try this
With wsSource
.Range(.Range("A2"), .Range("C2").End(xlDown)).Copy
wsDestination.Range("A3").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
Whenever in doubt, record a macro ;)

Macro - Copy and Paste

My company only uses MS Office 2003 products so I have to stick to it. Because of the nature of my job, i need to use a lot of "copy and paste" function. The source data is mostly from the website and i paste the data into a cell in Excel. The problem is clipboard keeps source formatting and it reflects on the cell when i paste it. That is really troublesome to remove the source format by selecting option "Paste as Text" every time i user copy and paste. SO i decided to use Macro. The Macro works perfectly when i try to copy and paste from website to excel, but when i copy and paste from Excel to the same work Sheet it throws an error.
This is the code i use for copy and paste from website to excel without source formatting.
Sub Paste_without_any_formatting()
ActiveSheet.PasteSpecial Format:="Text"
End Sub
I want to add another code for copy and paste from excel to the same work Sheet like this.
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
How can i put these two codes together? I want to make these happen magically when i press Ctrl+V. Can anyone help me?
This is the most simplest way to achieve it.
Sub Sample()
On Error GoTo Whoa1
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Exit Sub
Pastetext:
On Error GoTo Whoa2
ActiveSheet.PasteSpecial Format:="Text"
Exit Sub
Whoa1:
Resume Pastetext
Whoa2: '<~~ If both Paste method fails then show message. Ex: Image in Clipboard
MsgBox err.Description
End Sub
There is one more way where you try to ascertain the clipboard data type and then paste accordingly.