Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Error in Macro

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Error in Macro

It still says data type mismatch, but I also wanted it to copy data from a
closed workbook, for instance, I wanted so that when I type the name of the
file in the input box it will open the workbook which i typed in the input
box and then copy the range that's already specified in the macro to the main
workbook, is there anyway of doing that as well?

"Joel" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Error in Macro

It help if you can tell me which line of code fails! Yes, you can copy data
from one workbook to another very easily. It looks like your code should
work. Lets get past the first error and see if the rest of the code works.

"drinese18" wrote:

It still says data type mismatch, but I also wanted it to copy data from a
closed workbook, for instance, I wanted so that when I type the name of the
file in the input box it will open the workbook which i typed in the input
box and then copy the range that's already specified in the macro to the main
workbook, is there anyway of doing that as well?

"Joel" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Error in Macro

Actually nevermind for the first error, I corrected it, but for the second
part I tried utilizing it to find the workbook based what the name of the
workbook I typed in the input box, when it gets that information it should
copy the data from the workbook I typed in the inputbox, copy it and paste it
to the main workbook, but instead it's just skipping over that line of code
the one that enables it to copy and just going straight to the one that says

"If wbkCopyTo Is Nothing Then
MsgBox "Sorry... Can't find the destination file."

So kind of at a loss here



"Joel" wrote:

It help if you can tell me which line of code fails! Yes, you can copy data
from one workbook to another very easily. It looks like your code should
work. Lets get past the first error and see if the rest of the code works.

"drinese18" wrote:

It still says data type mismatch, but I also wanted it to copy data from a
closed workbook, for instance, I wanted so that when I type the name of the
file in the input box it will open the workbook which i typed in the input
box and then copy the range that's already specified in the macro to the main
workbook, is there anyway of doing that as well?

"Joel" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
naming tab macro error runtime error 1004 D Excel Programming 3 February 28th 05 01:32 AM
Macro 'Automation error' with ChemOffice Excel macro Stew Excel Programming 0 October 27th 03 08:26 PM


All times are GMT +1. The time now is 01:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"