PDA

View Full Version : Solved: How to use str?



genracela
07-11-2010, 07:23 PM
I'm trying to copy data from one file to another.

My filename is in C1.

I copied a code and modified it based on my requirements, but unfortunately it returned an error on this line:
Workbooks("str" & ".xls").Sheets("sheet1").Range("A1: 5000").Copy


Option Explicit

Sub CopyTo()
Dim str As String
str = Range("C1").Value
Workbooks("str" & ".xls").Sheets("sheet1").Range("A1:D5000").Copy
ThisWorkbook.Sheets("Data").Range("A3").PasteSpecial Paste:=xlPasteValues
End Sub

Thanks!

mikerickson
07-11-2010, 10:04 PM
Try
Workbooks (str & ".xls")....

"str" is the explicit string "str"
str is the value of the variable, in that code, the value that is in C1.

genracela
07-15-2010, 06:19 PM
Thank you Mike!