VBA Copy Paste Special - vba

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.

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

Excel VBA Vlookup where user chooses what cells

I am creating a macro to do a vlookup between 2 different sheets within the same workbook, but sometime the layout of the cells changes so I wish to be able to add a dialog box that will allow the user to select what they are looking for and what list they would like to compare against but am not sure how to do this.
This is my code thus far:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-59],ONCE!C[-49],1,0)"
Range("BI2").Select
Selection.AutoFill Destination:=Range("BI2:BI208032")
Range("BI2:BI208032").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
Thanks in advance
You can use InputBox like this:
myValue = InputBox("Give me some input")

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

Macro to copy values only from one sheet to another

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

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 ;)