peterrudge
New Member
- Joined
- Nov 6, 2011
- Messages
- 17
I regularly import CSV file data into an excel template. One of the columns in the template contains a material name. The material values are in the following format:
"3/4 Int White Oak/Maple Mel"
"3/4 Ext White Oak/Maple Mel"
"Door/Drawer White Oak/Maple Mel"
I want to reword them as:
[TABLE="width: 1000, align: center"]
<tbody>[TR]
[TD]"3/4 Maple Mel"[/TD]
[TD]If second word is "Int" return the first word, and the everything right of "/"[/TD]
[/TR]
[TR]
[TD]"3/4 White Oak"[/TD]
[TD]If second word is "Ext" return the first word, and the everything left of "/" to the second space in the string[/TD]
[/TR]
[TR]
[TD]"Door/Drawer White Oak/Maple Mel"[/TD]
[TD]If second word isn't "Int" or "Ext" dont chage the text[/TD]
[/TR]
</tbody>[/TABLE]
I currently get this done with a helper column and a long formula.
I would like to have this done as part of the import process with VBA so I don't need a helper column and the value in the cell is text not a formula.
Here is a link to a sample workbook. https://skydrive.live.com/redir?page=view&resid=8EB78428BD73FB8!4102&authkey=!AFvtx0k2BWtD8-w
The helper column is "K" the original material values are in "F"
I have no experience with VBA but the code I have put together from Googling is below (I haven't gotten it to run yet). To use this code I would have to change the material text to this format:
"3/4-Int-White Oak-Maple Mel"
Any ideas on VBA to parse the text ideally as part of the import process?
"3/4 Int White Oak/Maple Mel"
"3/4 Ext White Oak/Maple Mel"
"Door/Drawer White Oak/Maple Mel"
I want to reword them as:
[TABLE="width: 1000, align: center"]
<tbody>[TR]
[TD]"3/4 Maple Mel"[/TD]
[TD]If second word is "Int" return the first word, and the everything right of "/"[/TD]
[/TR]
[TR]
[TD]"3/4 White Oak"[/TD]
[TD]If second word is "Ext" return the first word, and the everything left of "/" to the second space in the string[/TD]
[/TR]
[TR]
[TD]"Door/Drawer White Oak/Maple Mel"[/TD]
[TD]If second word isn't "Int" or "Ext" dont chage the text[/TD]
[/TR]
</tbody>[/TABLE]
I currently get this done with a helper column and a long formula.
I would like to have this done as part of the import process with VBA so I don't need a helper column and the value in the cell is text not a formula.
Here is a link to a sample workbook. https://skydrive.live.com/redir?page=view&resid=8EB78428BD73FB8!4102&authkey=!AFvtx0k2BWtD8-w
The helper column is "K" the original material values are in "F"
I have no experience with VBA but the code I have put together from Googling is below (I haven't gotten it to run yet). To use this code I would have to change the material text to this format:
"3/4-Int-White Oak-Maple Mel"
Code:
Dim KCDMat() As Variant
Dim Cell As Range
With ActiveSheet
For Each Cell In Intersect(.Range("F:F"), .UsedRange)
'Split up the words in the text string
KCDMat() = Split(Cell.Value, "-")
'check to see if interior material
If KCDMat(1) = "Int" Then
'substitute interior material for "Int"
Cell.Value = KCDMat(0, 3)
'check to see if exterior material
ElseIf KCDMat(1) = "Ext" Then
'substitute exterior material for "Ext"
Cell.Value = KCDMat(0, 2)
Else
End If
Next
End With
Any ideas on VBA to parse the text ideally as part of the import process?