Solved

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

Posted on 2011-09-04
2
206 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 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now