Removing #Name Entries

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,842
Office Version
  1. 365
Platform
  1. Windows
I have the following code to clean a download CSV file, but it is leaving entries that has #Name which then requries a manual filter. How can I run the same code to remove these lines. The code I use is shown below@

Sub strip2()
'*********************************************
'The following code was created by Trevor G 31 March 2010
'Email
'The following code will strip away any text entries
'Or blank rows in the database extract
'Then it will convert the numbers in the MI Reference Column (A)
'Into A Number format
'*********************************************
Dim lngRow As Long
Range("K1048576").Select 'Range("k65536").Select
ActiveCell.End(xlUp).Select
lngRow = ActiveCell.Row + 1
Range("A2").Select
Do Until ActiveCell.Row = lngRow
If Not IsNumeric(ActiveCell.Value) Or ActiveCell.Value = "" Then
ActiveCell.EntireRow.Delete
lngRow = lngRow - 1
Else
ActiveCell.Offset(1, 0).Select
End If
Loop

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
1. Selecting is rarely needed in vba and can slow your code considerably.

2. Looping through worksheet cells can also be quite slow.

Try this alternative approach in a copy of your workbook.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> strip3()<br>    <SPAN style="color:#00007F">Dim</SPAN> LR <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    LR = Range("K" & Rows.Count).End(xlUp).Row<br>    Columns("A").Insert<br>    <SPAN style="color:#00007F">With</SPAN> Range("A2:A" & LR)<br>        .Formula = "=IF(ISNUMBER(B2),1,"""")"<br>        .Value = .Value<br>        .EntireRow.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo, _<br>            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _<br>            DataOption1:=xlSortNormal<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>        .SpecialCells(xlCellTypeBlanks).EntireRow.Delete<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Columns("A").Delete<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Upvote 0
Peter thank you very much for looking at my thread and suggesting a solution. I had to leave work quickly (from London) to return home due to family crisis and checked it out on the train back to Tamworth.

A Much quicker method than the approach I was taking.

I am very grateful to you. This will be implemented on my return.:)
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top