+ Reply to Thread
Results 1 to 5 of 5

Repeating Macro through Cells and Worksheets

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    29

    Repeating Macro through Cells and Worksheets

    Hi all,

    I am having some issues with repeating the macro using the 'next' function. What I want to do is change any cell that has a '0' in it to '1E-10'

    I currently have this so far for one sheet but am having some difficulty exiting the loop and going to the next worksheet -

    Sub Replace0()

    Dim ActiveCell As Variant

    For Each ActiveCell In Range("A1:AI1000")

    If ActiveCell.Value = "0" Then

    ActiveCell.Value = "0.0000000001"

    End If

    Next

    End Sub

    Any help would be much appreciated.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,747

    Re: Repeating Macro through Cells and Worksheets

    Welcome to the Forum Strup!

    First, it is your first post so I will remind you of the rules (see below) but also answer your question. Please ensure you review the rules and observe them in future posts.

    I strongly recommend against using ActiveCell as a variable name because it is a built-in object in Excel VBA and you could really get tangled up with that.

    Do you really need to review every cell in the range A1:AI1000? An alternative might be to use CurrentSheet.UsedRange if you don't know in advance which cells are being used.
    Please Login or Register  to view this content.
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-30-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Repeating Macro through Cells and Worksheets

    Hello,

    Thanks for your reply and sorry for the layout.

    Whilst this works on a test spreadsheet, as soon as I use this module in my required worksheet (which has a variety of columns, text, etc), I recieve the following message - Run-time error '13': Type mismatch

    For -

    Please Login or Register  to view this content.
    Any ideas why?

    Thanks again!

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Repeating Macro through Cells and Worksheets

    Try one of these

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Repeating Macro through Cells and Worksheets

    Another:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Repeating macro for various worksheets to complete lines in consolidation sheet
    By RossChip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2013, 07:46 AM
  2. Running a Chart Macro on Selected Cells and Repeating It
    By Bantymom in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-15-2012, 03:38 PM
  3. [SOLVED] repeating a macro in every row (for multiple cells)
    By hluk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-30-2012, 03:16 AM
  4. Macro for repeating a set of steps in all the worksheets in a workbook
    By kkothar in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-17-2012, 01:54 AM
  5. Repeating macro procedure on several worksheets
    By Shandy720 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1