Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Crystal
 
Posts: n/a
Default Runtime error for macro that works in workbook created in

Hi there,

I created a macro to fill in fields and saved it in my personal workbook so
it could be used for all my workbooks. It works in the original workbook I
created it in, but when I try to open it in others, I get the 1004 runtime
error!

Is there something I'm doing wrong? All my fields are named, and when I run
it, it fills in the first field but gives me the error immediatly after.

Here's my code, hopefully someone can offer me help.
Thanks!
Crystal

Sub Macro1()
'
' FormFill Macro
'
Range("REQUESTORF").Select
ActiveCell.FormulaR1C1 = "Crystal"

Range("REQUESTORL").Select
ActiveCell.FormulaR1C1 = "Nassouri"

Range("ADDRESS").Select
ActiveCell.FormulaR1C1 = "Oakway"

Range("E2").Select
End Sub

  #2   Report Post  
JPW
 
Posts: n/a
Default

Two things: first, is your code in the right place? Where are you running from? Second, allow me to give you a hand. This code will
both eliminate your error and allow for some feedback to help determine what the problem is. Just assign a hotkey to this new
procedure and go! When it runs it will either inform you that it couldn't find any named ranges in the workbook, or it will tell you
which workbook it acted upon, the number of named ranges found and the number of "fields" filled (preferably 3, right?) -- any
problems let me know what the result is and we'll track it down. :)


Sub FillFields()

Dim aName As Name, aCount As Single, fCount As Single

aCount = 0
fCount = 0

For Each aName In ThisWorkbook.Names
aCount = aCount + 1
If UCase(aName.Name) = "REQUESTORF" Then
aName.RefersToRange.Formula = "Crystal"
fCount = fCount + 1
ElseIf UCase(aName.Name) = "REQUESTORL" Then
aName.RefersToRange.Formula = "Nassouri"
fCount = fCount + 1
ElseIf UCase(aName.Name) = "ADDRESS" Then
aName.RefersToRange.Formula = "Oakway"
fCount = fCount + 1
End If
Next aName

If aCount = 0 Then
MsgBox prompt:="Couldn't find any of the fill fields!", _
Title:="FillFields Error"
Else
MsgBox prompt:="Processed workbook " & ThisWorkbook.Name _
& vbNewLine & "Found " & aCount & " named ranges; filled " _
& fCount & " fields.", Title:="FillFields Result"
End If

End Sub




"Crystal" wrote in message ...
Hi there,

I created a macro to fill in fields and saved it in my personal workbook so
it could be used for all my workbooks. It works in the original workbook I
created it in, but when I try to open it in others, I get the 1004 runtime
error!

Is there something I'm doing wrong? All my fields are named, and when I run
it, it fills in the first field but gives me the error immediatly after.

Here's my code, hopefully someone can offer me help.
Thanks!
Crystal

Sub Macro1()
'
' FormFill Macro
'
Range("REQUESTORF").Select
ActiveCell.FormulaR1C1 = "Crystal"

Range("REQUESTORL").Select
ActiveCell.FormulaR1C1 = "Nassouri"

Range("ADDRESS").Select
ActiveCell.FormulaR1C1 = "Oakway"

Range("E2").Select
End Sub



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
HOW DO I SUM TWO CELLS FROM ONE WORKBOOK TO ANOTHER WORKBOOK? Bill O'Neal Excel Worksheet Functions 8 August 14th 09 11:36 PM
I cannot paste from one workbook to another. Copy works, paste do. JimmyMc Excel Discussion (Misc queries) 1 June 10th 05 03:54 PM
Linking a cell to another workbook cell based on a variable name Brian Excel Discussion (Misc queries) 6 June 1st 05 11:54 PM
Unprotect Workbook Kent Excel Discussion (Misc queries) 1 February 4th 05 01:07 AM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


All times are GMT +1. The time now is 06:56 PM.

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

About Us

"It's about Microsoft Excel"