Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
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 | Excel Worksheet Functions | |||
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 | Excel Discussion (Misc queries) | |||
Excel 2003 Macro Error - Runtime error 1004 | Excel Discussion (Misc queries) | |||
naming tab macro error runtime error 1004 | Excel Programming | |||
Macro 'Automation error' with ChemOffice Excel macro | Excel Programming |