repeat checking and empty cell

kbenjamin

New Member
Joined
Jan 15, 2014
Messages
4
Hi All,

Hopefully somebody can help me to write a vba repeat until data end?

if D2=1, column AH2 & AI2 value stay still, if D2=empty, column AH2 & AI2 blank cell/Clear cell content

Example:
From
DAHAI
10.128.25
0.128.25
0.128.25
0.128.25
10.011.85
0.011.85

<TBODY>
</TBODY>



To this
DAHAI
10.128.25
10.011.85

<TBODY>
</TBODY>

Many Thanks!!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
kbenjamin,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?


Sample raw data:


Excel 2007
DAHAI
1
210.128.25
30.128.25
40.128.25
50.128.25
610.011.85
70.011.85
8
Sheet1


After the macro:


Excel 2007
DAHAI
1
210.128.25
3
4
5
610.011.85
7
8
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub Check_D_empty_cells()
' hiker95, 01/15/2014, ME750795
Dim c As Range, lr As Long
Application.ScreenUpdating = False
lr = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
For Each c In Range("D2:D" & lr)
  If c = "" Then
    Range("AH" & c.Row).Resize(, 2).ClearContents
  End If
Next c
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Check_D_empty_cells macro.
 
Upvote 0
Welcome to the board and Hiker95 has already provided you a VBA solution as you requested, but being the simple person I am (do know VBA yet...:) ) and for future use here is how I would do it. Insert a new column A and auto number it from 1 to the end of your data. then Sort all data based on column D so that all the cells containing 1 are at the top, all the remaining rows you can simply highlight and delete the data. and then resort all you data based on your column A numbering and then delete A. perhaps not as clean and fast as a VBA macro but then again if Hiker95 is not around to help this is how you can accomplish it. Don
 
Upvote 0
kbenjamin,

With the same screenshots as my last reply.

Here is a shorter, and, probably faster macro without any looping.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub Check_D_empty_cells_V2()
' hiker95, 01/15/2014, ME750795
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
On Error Resume Next
Range("D2:D" & lr).SpecialCells(xlCellTypeBlanks).Offset(, 30).ClearContents
Range("D2:D" & lr).SpecialCells(xlCellTypeBlanks).Offset(, 31).ClearContents
On Error GoTo 0
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Check_D_empty_cells_V2 macro.
 
Upvote 0
Drrellik,

(do know VBA yet... :))

Hope there is something below that will help you.


Training / Books / Sites as of 1/15/2014

What Is VBA?
VBA is an acronym for Visual Basic for Applications. VBA should not be confused with VB, which is standard Visual Basic. Visual Basic for Applications is a programming feature designed by Microsoft for use with their Microsoft Office

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
MrExcel's Products: Books, CDs, Podcasts

There are over 1800 Excel videos/tutorials here:
ExcelIsFun - YouTube

Getting Started with VBA.
DataPig Technologies

If you are serious about learning VBA try
Macros Made Easy for Microsoft Excel

Excel Tutorials and Tips - VBA - macros - training
Excel Tutorial | Excel Tips | Excel Articles

Free VBA Course
Free VBA Course

Excel 2007 VBA materials to learn here:
VBA for Excel 2007 tutorial-VBA programming?

Here's a good primer on the scope of variables.
Understanding Scope

Using Variables in Excel VBA Macro Code
Excel VBA Variables. Using Variables in Excel VBA Macro Code

See David McRitchie's site if you just started with VBA
Getting Started with Macros and User Defined Functions

What is a VBA Module and How is a VBA Module Used?
What Is A VBA Module and how is a VBA Module Used?

Events And Event Procedures In VBA
Events In Excel VBA

Here is a good introductory tutorial using a VBA Class:
Classes In VBA

Ron's Excel Tips
Excel for Windows Tips

Ron de Bruin's Mail from Excel and make/mail PDF files (Windows)
Mail from Excel and make/mail PDF files (Windows)

Anthony's Excel VBA Page - Excel Application - Excel Consultant - Excel Consulting (see 3 tutorials in Excel VBA Basic Tutorial Series)

BET: Microsoft Excel Visual Basic

Debugging VBA
Debug Excel VBA Macro Code
TechBookReport - Debugging Excel VBA Code

Start at the beginning...

Creating An XLA Add-In For Excel, Writing User Defined Functions In VBA
Creating An XLA Add In

Creating custom functions
Creating custom functions - Excel - Office.com

Writing Your First VBA Function in Excel
Writing Your First VBA Function in Excel | Custom Functions

VBA for Excel (Macros)
Excel Macros (VBA) Tutorial

Excel Macros Tutorial
Excel Macros (VBA) Tutorial

Excel Macros & Programming
EXCEL Macros Tutorial

VBA Lesson 11: VBA Code General Tips and General Vocabulary
VBA for Excel macros language

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Beyond Excel's recorder

Helpful as a simple concise reference for the basics, and, using the macro recorder is endlessly powerful.
MS Excel: Cells

Learn to debug:
Debugging VBA

How To: Assign a Macro to a Button or Shape
How To: Assign a Macro to a Button or Shape - Peltier Tech Blog

User Form Creation
http://www.contextures.com/xlUserForm01.html

When To Use a UserForm & What to Use a UserForm For
When to use Userform & What To Use Them For. Excel Training VBA 2 lesson 2

Excel Tutorials / Video Tutorials - Functions
http://www.contextures.com/xlFunctions02.html

How to insert Buttons, radio buttons and check boxes in Excel
How to insert Buttons, radio buttons and check boxes in Excel - Bing Videos

INDEX MATCH - Excel Index Function and Excel Match Function
http://www.contextures.com/xlFunctions03.html

Multi or two way vlook up and index match tutorial
Get Digital Help - Excel formulas, array formulas, vba, charts, pivot tables, templates and much more.

Excel Data Validation
http://www.contextures.com/xlDataVal08.html#Larger
http://www.contextures.com/excel-data-validation-add.html

Excel -- Data Validation -- Create Dependent Lists
http://www.contextures.com/xlDataVal02.html

Your Quick Reference to Microsoft Excel Solutions
XL-CENTRAL.COM : For your Microsoft Excel Solutions

New! Excel Recorded Webinars
DataPig Technologies

Fuzzy Matching - new version plus explanation

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
Programming In The VBA Editor

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

John Walkenbach's power programming with Excel books.

by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
Professional Excel Development

by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
Excel 2002 VBA: Programmers Reference

"Professional Excel Development" by Rob Bovey, Dennis Wallentin, Stephen Bullen, & John Green

DonkeyOte: My Recommended Reading, Volatility
Volatile Excel Functions -Decision Models

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Arrays
VBA Array Basics
VBA Arrays
Excel: Introduction to Array Formulas - Xtreme Visual Basic Talk
Excel VBA Chpter 21: Array in Excel VBA

Array Dimensions in Visual Basic - Working with Dimensions (code and graphics)
Array Dimensions in Visual Basic

Shortcut Keys in Excel 2000 through 2007

Pivot Intro
Using Pivot Tables and Pivot Charts in Microsoft Excel
Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
Getting Started with Pivot Tables
http://www.contextures.com/xlPivot01.html#Start
Overview of PivotTable and PivotChart reports
Overview of PivotTable and PivotChart reports - Excel - Office.com
Build a Pivot Table in Excel VBA
Excel VBA - Build A Pivot Table In Excel VBA Tutorials

Email from XL - VBA
Mail from Excel example pages

Outlook VBA
Writing VBA code for Microsoft Outlook

Excel Function Dictionary by Peter Noneley
http://www.xlfdic.com/
www.xlfdic.com Excel Function Dictionary 150 example functions and formula.

Function Translations
Excel 2007 function name translations - Dictionary Chart Front Page

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
Excel Dashboards - Templates, Tutorials, Downloads and Examples | Chandoo.org - Learn Microsoft Excel Online
Excel Dashboards - Templates, Tutorials, Downloads and Examples | Chandoo.org - Learn Microsoft Excel Online
Free Microsoft Excel Dashboard Widgets to Download
AJP Excel Information - Gauge

Excel Dashboard / Scorecard Ebook
Excel Dashboards and Scorecards Ebook | How to Create Dashboards in Excel

Mike Alexander from Data Pig Technologies
Excel 2007 Dashboards and Reports For Dummies: Michael Alexander: 9780470228142: Amazon.com: Books

Templates
CPearson.com Topic Index
http://www.contextures.com/excel-template-golf-scores.html
Free Microsoft Excel Template Links & Search Engine

Microsoft Excel Cascading Listboxes Tutorial
Microsoft Excel Cascading Listboxes Tutorial - YouTube

Date & Time stamping:
McGimpsey & Associates : Excel : Time and date stamps

Get Formula / Formats thru custom functions:
Show FORMULA or FORMAT of another cell

A nice informative MS article "Improving Performance in Excel 2007"
Improving Performance in Excel 2007

Progress Meters
AJP Excel Information - Progress meters
xcelfiles.com

How to convert text to numbers in Excel
How to convert text to numbers in Excel

How to parse data from the web - Brett Fret has a video in YouTube
Excel VBA - Easily parse XML data from a file or website using XML Maps - YouTube

And, as your skills increase, try answering threads on sites like:
MrExcel.com | Excel Resources | Excel Seminars | Excel Products
Excel Help Forum
Excel Templates | Excel Add-ins and Excel Help with formulas and VBA Macros
http://www.vbaexpress.com
Excel, Access, PowerPoint and Word VBA Macro Automation Help

If you are willing to spend money for the training, then something here should work for you...
Amazon.com: excel tutorial dvd

Advanced Excel Training - Online Excel Course
http://www.udemy.com/advanced-excel/
 
Last edited:
Upvote 0
kbenjamin,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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