Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2007, 05:45 AM
Authorized User
 
Join Date: Apr 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default find character % and format column

Hi,

I want to format the columns into percentage where in the field name the "%" character exsist. I made a script which looks for the % character and formats the column accordingly. The problem starts when it goes to anoter worksheet and cannot the percentage character (which is good) but how can I step out of this error and continue to the next worksheet. I tried on error resume next but the error keeps returning "Run time error 91"

This is the code:

Code:
Sub find()
'
'This section is to find an '%' character and change that column with the propper format

On Error GoTo errtestproc

'Worksheets(2).Activate
    Range("a1", Selection.End(xlToRight)).Select
    c = Selection.Columns.Count

    q = Selection.End(xlToRight).Address

    lastcolumnletter = Mid(q, 2, (InStr(2, q, "$")) - 2)

Do


    On Error Resume Next
     a = Cells.find(What:="%", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext).Address
 
 
 
    mycolumnletter = Mid(a, 2, (InStr(2, a, "$")) - 2)
    Range(mycolumnletter & "1").Select
    Columns(mycolumnletter & ":" & mycolumnletter).Select
    Selection.NumberFormat = "0%"

Loop While Not mycolumnletter = lastcolumnletter
Exit Sub

errtestproc:
    MsgBox "test"
    Resume


End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
find the FIRST USED row/column? crmpicco Excel VBA 3 July 23rd, 2013 12:52 PM
how to DataGridTextBoxColumn to format the column brad-jenny General .NET 3 September 7th, 2007 03:37 PM
column with one character - use Char or Varchar crmpicco MySQL 4 January 17th, 2006 07:35 AM
find the last used column crmpicco Excel VBA 2 May 20th, 2005 08:14 AM
Find column in datagrid Lesviper VB How-To 0 March 9th, 2005 07:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.