Solved

How do I get a macro to do nothing if column is blank?

Posted on 2008-10-02
2
165 Views
Last Modified: 2013-11-25
I have a macro to convert numbers with decimal places in column A to whole integers.  I want the macro, if ran, to do nothing if column A contains no data.  This macro is ran when a custom button in the Standard toolbar is clicked.
Public Sub RPM_to_MSProject()
 

   Dim Cell As Range
 

   For Each Cell In Intersect(ActiveSheet.[A3:A65536], ActiveSheet.UsedRange)
 

      Cell = Int(Len(Cell) / 2.1)
 

   Next Cell
 

End Sub

Open in new window

0
Comment
Question by:szadroga
2 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 250 total points
ID: 22624746
something like this

Cheers

Dave


Public Sub RPM_to_MSProject()

   Dim Cell As Range

   If Application.WorksheetFunction.CountA(Columns("A")) = 0 Then Exit Sub

   For Each Cell In Intersect(ActiveSheet.[A3:A65536], ActiveSheet.UsedRange)

      Cell = Int(Len(Cell) / 2.1)

   Next Cell

End Sub

Open in new window

0
 
LVL 59

Assisted Solution

by:Saurabh Singh Teotia
Saurabh Singh Teotia earned 250 total points
ID: 22624785
Or something like this....

Saurabh...
Public Sub RPM_to_MSProject()

 

   Dim Cell As Range

 

   For Each Cell In Intersect(ActiveSheet.[A3:A65536], ActiveSheet.UsedRange)

 if(cell.value<>"") then

      Cell = Int(Len(Cell) / 2.1)

 end if

   Next Cell

 

End Sub

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

746 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

12 Experts available now in Live!

Get 1:1 Help Now