rollingzep
Board Regular
- Joined
- Nov 18, 2013
- Messages
- 214
- Office Version
- 365
- Platform
- Windows
if Text.Length([Code]) <= 9 then [Code] else null
Is it possible to do it using VBA?With out data which I can manipulate (can't manipulate data in pictures), I will give you the steps I would use.
1. Load your CSV file to Power Query (Get and Transform Data found on the Data Tab)
2. Add a column and test for length.
where Code is the name of the fieldPower Query:if Text.Length([Code]) <= 9 then [Code] else null
3. Highlight the new column and filter out Nulls
4. Close and Load to your Native Excel Spreadsheet.
Note. Based upon your note and visual, it appears that you want to keep those that are less than or equal to 9 digits while you indicate the opposite in your statement.
Have a look here. You should be able to adapt the solution to do what you want:Is it possible to do it using VBA?
Sub ImportData()
Dim R As Long
Dim C As Integer
Dim sDelim As String
Dim sRaw As String
Dim ReadArray() As String
Dim vFileName As Variant
sDelim = ","
vFileName = Application.GetOpenFilename("Comma Separated Files (*.csv),*.csv")
If vFileName <> False Then
Worksheets.Add
Open vFileName For Input As #1
R = 1
Do While Not EOF(1)
Line Input #1, sRaw
ReadArray = Split(sRaw, sDelim, 35, vbTextCompare)
If Len(ReadArray(0)) = 9 Then
Cells(R, 1).Value = ReadArray(0)
R = R + 1
End If
Loop
Close #1
End If
MsgBox "Import complete!"
End Sub