?
Solved

Look for text entries in specific column, move up one cell and delete that cell

Posted on 2011-09-04
2
Medium Priority
?
218 Views
Last Modified: 2012-05-12
Dear Experts:

I would like to achieve the following using VBA:

Go thru column B of the (used range of the ) active worksheet and look for text entries (numbers formatted as text do not count).
If found move up one cell and delete the contents of that cell. Do Loops.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

I have attached a sample file for your  convenience with detailed explanations.


 Loop-And-Delete.xlsx
0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 2000 total points
ID: 36480437
Hi,

Try

Sub kTest()

    Dim k, i As Long, cAddr As String, r As Range
   
    Const StartCell As String = "B7" '<<=== adjust this to suit
   
    Set r = Range(CStr(StartCell))
   
    k = Range(r, Cells(Rows.Count, r.Column).End(xlUp))
   
    For i = 2 To UBound(k, 1)
        If Not IsNumeric(k(i, 1)) Then
            cAddr = cAddr & "," & Cells(i - 1, 1).Address(0, 0)
            If Len(cAddr) > 240 Then
                r.Range(CStr(Mid$(cAddr, 2))).ClearContents
                cAddr = vbNullString
            End If
        End If
    Next
    If Len(cAddr) > 1 Then
        r.Range(CStr(Mid$(cAddr, 2))).ClearContents
    End If

End Sub

Kris
0
 

Author Closing Comment

by:AndreasHermle
ID: 36480843
Hi Kris,

great job. Works like a charm. Thank you very much for your professional help. Regards,  Andreas
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question