Solved

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

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

777 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