Excel Macros

  • Thread starter DLinkage
  • Start date
  • #1
19
0

Main Question or Discussion Point

I'm trying to read in a file's filename and append part of the filename to a certain range of cells. This is to say if the filename was "ABC12X.txt"
and another filename was "ABC13X.txt", then how could I obtain the values "12" and "13" given the filename information alone? Thanks
 

Answers and Replies

  • #2
29
0
Do some string manipulations i guess...I forgot my vb :(
 
  • #4
hotvette
Homework Helper
990
3
I'm trying to read in a file's filename and append part of the filename to a certain range of cells. This is to say if the filename was "ABC12X.txt"
and another filename was "ABC13X.txt", then how could I obtain the values "12" and "13" given the filename information alone? Thanks
If what you are trying to extract is always the 4th-5th characters, you can use the mid function:

Sub test()
Dim s1 As String
s1 = "ABC12X.txt"
Debug.Print Mid(s1, 4, 2) 'result is 12
End Sub
If you need addition help, the 'Office Development' forum within the following VB forum is great:

http://www.vbforums.com/index.php

Good luck. :smile:
 
Last edited:

Related Threads on Excel Macros

  • Last Post
Replies
18
Views
4K
  • Last Post
Replies
2
Views
14K
  • Last Post
Replies
1
Views
500
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
2
Views
7K
  • Last Post
Replies
20
Views
1K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
1
Views
11K
  • Last Post
Replies
4
Views
748
  • Last Post
Replies
2
Views
3K
Top