Obtaining Values from Filenames

  • Thread starter Thread starter DLinkage
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around extracting specific values from filenames, particularly focusing on how to obtain numerical values embedded within the filenames, such as "12" and "13" from "ABC12X.txt" and "ABC13X.txt". The context includes programming techniques, specifically in Visual Basic for Applications (VBA).

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant suggests using string manipulations to extract the desired values from the filenames.
  • Another participant provides a specific VBA code snippet using the Mid function to extract characters from the filename, assuming the values are always located at the 4th and 5th positions.
  • A third participant shares a link to a resource that may assist with string manipulation in Excel.

Areas of Agreement / Disagreement

There is no explicit consensus on the best method to extract the values, as participants provide different approaches and resources without resolving which is superior.

Contextual Notes

The discussion assumes that the values to be extracted are consistently located at specific positions within the filenames, but this may not hold for all potential filenames.

Who May Find This Useful

Individuals interested in programming with VBA, particularly those looking to manipulate strings or automate tasks in Excel.

DLinkage
Messages
17
Reaction score
0
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
 
Technology news on Phys.org
Do some string manipulations i guess...I forgot my vb :(
 
DLinkage said:
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:

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 6 ·
Replies
6
Views
6K
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K