Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help: Macro Copy Active Cell to Range Name, loop

I am running the following code that I got from this newsgroup,

......
Sub NameMe()

Dim strName As String
Dim strAddr As String


strName = ActiveCell.Value
strAddr = ActiveCell.Address(, , xlR1C1)


ActiveWorkbook.Names.Add _
Name:=strName, _
RefersToR1C1:="=Sheet1!" & strAddr

End Sub
.....

For some reason the Names.Add function will not accept the string. It
will accept strings which I manually type, eg. "typedname", but not
strings set to the ActiveCell.Value.

Is there some way to work around this? Can I add quotes to the string
somehow? Am I barking up the wrong tree?

Any help is appreciated,
Petur G

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help: Macro Copy Active Cell to Range Name, loop

Before you go too far, how about sharing what's in Activecell.value?

Maybe it isn't a valid name????

No spaces. No names that look like addresses. No invalid characters...

Debug.print "***" & activecell.value & "***"

may help pinpoint the problem.

" wrote:

I am running the following code that I got from this newsgroup,

.....
Sub NameMe()

Dim strName As String
Dim strAddr As String

strName = ActiveCell.Value
strAddr = ActiveCell.Address(, , xlR1C1)

ActiveWorkbook.Names.Add _
Name:=strName, _
RefersToR1C1:="=Sheet1!" & strAddr

End Sub
....

For some reason the Names.Add function will not accept the string. It
will accept strings which I manually type, eg. "typedname", but not
strings set to the ActiveCell.Value.

Is there some way to work around this? Can I add quotes to the string
somehow? Am I barking up the wrong tree?

Any help is appreciated,
Petur G


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help: Macro Copy Active Cell to Range Name, loop

On Mar 29, 7:52 pm, Dave Peterson wrote:
Before you go too far, how about sharing what's in Activecell.value?

Maybe it isn't a valid name????

No spaces. No names that look like addresses. No invalid characters...

Debug.print "***" & activecell.value & "***"

may help pinpoint the problem.





" wrote:

I am running the following code that I got from this newsgroup,


.....
Sub NameMe()


Dim strName As String
Dim strAddr As String


strName = ActiveCell.Value
strAddr = ActiveCell.Address(, , xlR1C1)


ActiveWorkbook.Names.Add _
Name:=strName, _
RefersToR1C1:="=Sheet1!" & strAddr


End Sub
....


For some reason the Names.Add function will not accept the string. It
will accept strings which I manually type, eg. "typedname", but not
strings set to the ActiveCell.Value.


Is there some way to work around this? Can I add quotes to the string
somehow? Am I barking up the wrong tree?


Any help is appreciated,
Petur G


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Thank you, Dave.

You were right, there were spaces in the string. Obviously, I am new
to VBA and the usenet group.


For anyone else reading this, here is some code to remove spaces,
which is available at: (http://www.fontstuff.com/vba/
vbatut05.htm#removespaces)

Public Function RemoveSpaces(strInput As String)
' Removes all spaces from a string of text
Test:
If InStr(strInput, " ") = 0 Then
RemoveSpaces = strInput
Else
strInput = Left(strInput, InStr(strInput, " ") - 1) _
& Right(strInput, Len(strInput) - InStr(strInput, " "))
GoTo Test
End If
End Function

Thanks again,
Petur G

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help: Macro Copy Active Cell to Range Name, loop

Another way to remove spaces from a string:

dim myStr as string
mystr = "h i th er e "
mystr = replace(mystr," ","")
msgbox mystr

Replace was added in xl2k.

before that, you could use:
mystr = application.substitute(mystr," ","")



" wrote:

On Mar 29, 7:52 pm, Dave Peterson wrote:
Before you go too far, how about sharing what's in Activecell.value?

Maybe it isn't a valid name????

No spaces. No names that look like addresses. No invalid characters...

Debug.print "***" & activecell.value & "***"

may help pinpoint the problem.





" wrote:

I am running the following code that I got from this newsgroup,


.....
Sub NameMe()


Dim strName As String
Dim strAddr As String


strName = ActiveCell.Value
strAddr = ActiveCell.Address(, , xlR1C1)


ActiveWorkbook.Names.Add _
Name:=strName, _
RefersToR1C1:="=Sheet1!" & strAddr


End Sub
....


For some reason the Names.Add function will not accept the string. It
will accept strings which I manually type, eg. "typedname", but not
strings set to the ActiveCell.Value.


Is there some way to work around this? Can I add quotes to the string
somehow? Am I barking up the wrong tree?


Any help is appreciated,
Petur G


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Thank you, Dave.

You were right, there were spaces in the string. Obviously, I am new
to VBA and the usenet group.

For anyone else reading this, here is some code to remove spaces,
which is available at: (http://www.fontstuff.com/vba/
vbatut05.htm#removespaces)

Public Function RemoveSpaces(strInput As String)
' Removes all spaces from a string of text
Test:
If InStr(strInput, " ") = 0 Then
RemoveSpaces = strInput
Else
strInput = Left(strInput, InStr(strInput, " ") - 1) _
& Right(strInput, Len(strInput) - InStr(strInput, " "))
GoTo Test
End If
End Function

Thanks again,
Petur G


--

Dave Peterson
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
copy name from active sheet to cell - using macro or function dymek Excel Worksheet Functions 2 October 2nd 06 12:32 PM
need to Copy or Move to active cell from specified range kaream Excel Discussion (Misc queries) 2 December 14th 05 08:12 AM
To copy from a range in another sheet to the active cell raja Excel Programming 1 September 8th 05 04:47 PM
Macro Copy Active Cell to Range Name, loop zigstick Excel Programming 6 April 27th 05 07:55 PM
Macro to copy cell data to word document based on an active row? Brian Excel Programming 2 September 16th 04 01:55 PM


All times are GMT +1. The time now is 04:15 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"