Consulting

Results 1 to 5 of 5

Thread: Solved: Using is empty on a range

  1. #1
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location

    Solved: Using is empty on a range

    The goal is to highlight a range, run the macro, have all cells that are just #'s (not formulas) AND are not presently blank/empty multiplied by 1000.

    I'm getting an error on the If and I know it has to do with my use of IsEmpty but I'm not sure how to rectify.

    Thanks!

    [VBA]Option Explicit
    Sub puttothousands()
    Dim c As Range

    For Each c In Selection
    If c.HasFormula = False And c.IsEmpty = False Then
    c = c * 1000
    End If
    Next c
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub puttothousands()
    Dim c As Range

    For Each c In Selection
    If Not c.HasFormula And Not IsEmpty(c.Value) And IsNumeric(c.Value) Then
    c = c * 1000
    End If
    Next c
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Thanks for helping shake the rust off. First use of VBA in months...

  4. #4
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    Hi,

    A non-loop approach..

    [vba]Dim r As Range, tmp As Range
    Set r = Selection
    Set tmp = Range("iv1") ' a temporary cell
    tmp = 1000
    tmp.Copy
    On Error Resume Next
    r.SpecialCells(xlCellTypeConstants, 1).PasteSpecial , Operation:=xlMultiply
    On Error GoTo 0
    tmp.Clear
    Application.CutCopyMode = 0[/vba]

    HTH

  5. #5
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Ya I realized I could've done the paste special. The loop method is nice and more easily modified for adding additional operations in the future.

    Thanks!

Posting Permissions

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