Thread: Error in Macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Error in Macro

InpData is defined as an Integer but you probably need to input a string

from
Dim inpData As Integer
to
Dim inpData As String

"drinese18" wrote:

I'm trying to create a macro that will copy data from one sheet to another.
It should bring up a InputBox where you would input the name of the workbook,
find it within the specified directory and paste the data to that workbook,
but I'm getting some errors within it, my code can be seen below:

Sub CopyData()

Dim rngCopyFrom As Range
Dim wbkCopyTo As Workbook
Dim rngCopyTo As Range
Dim inpData As Integer

inpData = InputBox(Prompt:="Enter Market Name", _
Title:="Market Name", Default:="Enter Market Name here")

If inpData = "Enter Market Name here" Or _
inpData = vbNullString Then
Exit Sub
Else

On Error Resume Next
Set wbkCopyTo = Workbooks(inpData)
If wbkCopyTo Is Nothing Then
Set wbkCopyTo = Workbooks.Open("C:\Documents and
Settings\jermaine_wanyou\Desktop\FACTBOOK SYSTEM\New Folder\")
On Error GoTo 0
If wbkCopyTo Is Nothing Then
MsgBox "Sorry... Can't find the destination file."
Else
Set rngCopyFrom =
ThisWorkbook.Sheets("Sheet1").Range("B4:M17")
Set rngCopyTo = wbkCopyTo.Sheets("Sheet1").Range("B4:M17")
End If
End If

End If

rngCopyTo.Value = rngCopyFrom.Value
wbkCopyTo.Close

End Sub

I'm very lost here, I'm not sure where exactly the error is coming from but
much help will be appreciated