View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Don't run if entire column is selected

I have run into the same thing.... My solution is to select a sub range based
on the range they have selected and the used range of the sheet. Here is how
I have set up to format all cells that intersect with the used range and the
selected range...
This function formats all cells at text

Public Sub Convert()
Dim rngCurrent As Range
Dim rngToSearch As Range

Set rngToSearch = Intersect(ActiveSheet.UsedRange, Selection)
If Not rngToSearch Is Nothing Then
'rngtosearch.select 'Uncomment this line to see what is going to be
converted

Application.Calculation = xlCalculationManual
For Each rngCurrent In rngToSearch
If Left(rngCurrent.Value, 1) < "=" Then

rngCurrent.NumberFormat = "@"
rngCurrent.Value = Trim(CStr(rngCurrent.Value))
End If
Next
Application.Calculation = xlCalculationAutomatic
End If
End Sub

Give this a try... It does not care if the user selects a single cell, a
range of cells, a column, a row...

HTH

"Elaine" wrote:

I have a small macro which formats selected cells. How I can get an error
message if an entire column is selected? I don't want all 65000 odd cells in
that column to be formatted.

I see that Columns("E:E").Select selects all cells in column E but I don't
know in advance which column will be selected as the format macro will work
on any block of cells selected.

Thanks.