1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Excel: Macro to divide specific cells by 100 with a filter

Discussion in 'Business Applications' started by rotvik, Feb 6, 2013.

Thread Status:
Not open for further replies.
  1. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    Hi

    I have a following macro:

    Code:
    Sub BondPrices()
    
        Selection.AutoFilter Field:=16, Criteria1:="BONDS"
        
        Range("S2:S10000").Select
        For Each cell In Selection
        If Not IsEmpty(cell) And IsNumeric(cell.Value) Then
        cell.Value = CDbl(cell.Value)
        cell.Value = cell.Value / 100
        End If
        Next cell
        
        Selection.NumberFormat = "0.00%"
        Selection.AutoFilter
    End Sub
    The problem is that every cell in the sheet gets divided by 100, not only the filtered cells (only BONDS).

    Any help would be greatly appreciated.

    Michael
     
  2. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    I've solved the problem myself by adding a line to the code that selects only visible cells:
    Code:
    Selection.SpecialCells(xlCellTypeVisible).Select
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1088403

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice