Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..


I found this formula, which was posted in 2004.

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CELL("filename",A1),1)-FIND("[",CELL("filename",A1),1)-1)


I wonder what does the cell A1 stand for? I removed it and it works
also ..

Matt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

and next question:

How can i get a macro to put this in a cell?

tried that:

Range("AA10").Select
ActiveCell.FormulaR1C1 =
"=MID(CELL('filename',A1),FIND('[',CELL('filename',A1),1)+1,FIND(']',CELL('filename',A1),1)-FIND('[',CELL('filename',A1),1)-1)"

results in errors ;;

Matt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Question about filename formula ..

Matt

See Bob Phillips' site for an explanation of why you need the A1.

http://www.xldynamic.com/source/xld.xlFAQ0002.html

Then go back and undo your deletion.


Gord Dibben Excel MVP

On 27 Sep 2005 14:00:27 -0700, "Matt" wrote:


I found this formula, which was posted in 2004.

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CELL("filename",A1),1)-FIND("[",CELL("filename",A1),1)-1)


I wonder what does the cell A1 stand for? I removed it and it works
also ..

Matt


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

cool :)

Now, how do I get this to work when a macro puts the forumla into a
cell? Does it need the R1C1 clutter for the A1? and all " replaced
with ' ?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

anybody? If pasted like that it causes errors :(

Range("AA10").Select
ActiveCell.FormulaR1C1 =
"=MID(CELL('filename',A1),FIND('[',CELL('filename',A1),1)+1,FIND(']',CELL('*filename',A1),1)-FIND('[',CELL('filename',A1),1)-1)"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

Got it!

(Tom)


Range("B1").Value =
left(activeworkbook.Name,len(ActiveWorkbook.name)-4)

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Question about filename formula ..

First of all, the formula does work, just not the way you have it. You have
a single apostrophe character ' instead of a " quote character. When using
VBA, however, you must use double quote "" signs. This will make it work,
however there is an easier way. How about ...

With ActiveWorkbook
Range("AA10").Value = Left(.Name, Len(.Name) - 4)
End With

This will give you the name without the ".xls" on the end. If you do want
that, how about ...

Range("AA10").Value = ActiveWorkbook.Name

HTH

--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)



"Matt" wrote in message
oups.com...
anybody? If pasted like that it causes errors :(

Range("AA10").Select
ActiveCell.FormulaR1C1 =
"=MID(CELL('filename',A1),FIND('[',CELL('filename',A1),1)+1,FIND(']',CELL('*filename',A1),1)-FIND('[',CELL('filename',A1),1)-1)"


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

I used this in my macro:

Dim tlm As String

tlm = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)

Range("Z3").Value = tlm


the problem is now that it will cut off leading zeros ... I understood
it shouldnt do that because I dimed it as string .. what do i have todo
to keep leading zeros?

Matt

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Question about filename formula ..

Matt,

With just one line, why even use a variable? Seems like a waste of 2 lines.
Are you using the variable in anything else? If more than two times, I'd
suggest using the variable, otherwise, it's pretty much a waste. Or if
you're going to provide multiple checks on it..

--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)


"Matt" wrote in message
oups.com...
I used this in my macro:

Dim tlm As String

tlm = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)

Range("Z3").Value = tlm


the problem is now that it will cut off leading zeros ... I understood
it shouldnt do that because I dimed it as string .. what do i have todo
to keep leading zeros?

Matt



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

I used it so I can dim it as string :)

I am not a programmer so I dont knwo how to do these things right...
but the problem is that it omits leading zeros :(

Matt



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

The macro opens a form with fields. One of the fields shows the
filename, ecept .xls., it cuts leadign zeros. When i abort the macro
and restart it it DOES show leading zeros ... how can that be? and how
can it be done so it shows them from the beginning ...?

Matt

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

I got it to work by adding this:

Range("Z2:Z3").Select
Selection.NumberFormat = "@"

not sure why .. my programming is like trial and error ;)

Matt

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Question about filename formula ..

You only need to set the format once, so you shouldn't need to run that
again. But in your code, instead of using the .Value property, you can use
the .Text property and it will use your leading zeros. If you're setting
the value of a cell as your variable, you can either set the format before
hand or use a single apostrophe preceeding the data entered into the cell.
The apostrophe will not show in the value of the cell, but denotes the
entire cell contents to be a textual value. This is primarily used when
using numerical values and wanting leading zeros to show up in the cell.
Note that this no longer becomes numerical, but textual, and will need to be
mitigated as such if using in any subsequent calculations.

Dim tlm As String
tlm = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
Range("Z3").NumberFormat = "@"

Range("Z3").Value = tlm
'or..
Range("Z3").Text = "'" & tlm

HTH

--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)




"Matt" wrote in message
ups.com...
I got it to work by adding this:

Range("Z2:Z3").Select
Selection.NumberFormat = "@"

not sure why .. my programming is like trial and error ;)

Matt



  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Question about filename formula ..

cool. works now:)


this doesnt work however:

Range("Z3").Text = "'" & tlm

Matt

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Question about filename formula ..

Oh, I'm sorry ...

Range("Z3").Value = "'" & tlm

Can't change the Text property but you can change the Value property. You
can only read the Text property. Sorry 'bout that.

--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)


"Matt" wrote in message
oups.com...
cool. works now:)


this doesnt work however:

Range("Z3").Text = "'" & tlm

Matt



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
Graphics Filename via Formula [email protected] Charts and Charting in Excel 0 July 22nd 08 10:36 PM
Filename in formula Kim Excel Discussion (Misc queries) 2 December 20th 07 07:06 PM
Retrieve filename question, again... µ New Users to Excel 3 February 15th 07 09:33 PM
Cell value/filename question... AlexJ Excel Discussion (Misc queries) 3 September 14th 05 09:36 PM
2 Question: Coloumn width, Filename nopfusch Excel Worksheet Functions 2 March 15th 05 07:43 PM


All times are GMT +1. The time now is 05:34 AM.

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"