Solved

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

Posted on 2008-10-02
2
168 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

932 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

20 Experts available now in Live!

Get 1:1 Help Now