+ Reply to Thread
Results 1 to 2 of 2

Macro adds number to entire selection, how to avoid adding to blank cells?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    452

    Macro adds number to entire selection, how to avoid adding to blank cells?

    I have recorded the below macro which will copy a value and the paste special and add it to the selection. The problem is that it is adding the value to blank cells when I do not want it to. Can this code be modified so that it doesn't add to blank cells. In the paste special dialog box I clicked skip blanks but this didn't change anything.

    Sub increasebets()
    '
    ' increasebets Macro
    ' This will send the cursor to the last completed spin, then down to the increase previous bet column for the next bet and add that to all the bets on the table.
    '
    
    '
        Range("F2").Select
        Selection.End(xlToRight).Select
        ActiveCell.Offset(7, 1).Range("A1").Select
        Selection.Copy
        Sheets("Bets").Select
        Union(Range( _
            "T20,T22,R22,P22,P24,R24,T24,O3:O25,Q3:Q25,S3:S25,V4:V22,X4:X22,AA4:AA15,P4,R4,T4,T6,R6,P6,P8,R8,T8,T10,R10,P10,P12,R12,T12,T14,R14,P14,P16" _
            ), Range("R16,T16,T18,R18,P18,P20,R20")).Select
        Range("T24").Activate
        Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlAdd, _
            SkipBlanks:=False, Transpose:=False
        Range("O1").Select
        Sheets("Spins").Select
        Range("F2").Select
    End Sub

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,264

    Re: Macro adds number to entire selection, how to avoid adding to blank cells?

    Change
    Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlAdd, _
            SkipBlanks:=False, Transpose:=False
    to this, if the cells have values and not formulas
    Selection.SpecialCells(xlCellTypeConstants, 23).PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlAdd, _
            SkipBlanks:=False, Transpose:=False
    or this, if the cells have formulas
    Selection.SpecialCells(xlCellTypeFormulas, 23).PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlAdd, _
            SkipBlanks:=False, Transpose:=False
    and if they are all values, you don't need to use all that selecting (though this is just a guess as to which sheet is active when the code is run)

        With Sheets("Bets")
        With Union(.Range( _
                   "T20,T22,R22,P22,P24,R24,T24,O3:O25,Q3:Q25,S3:S25,V4:V22,X4:X22,AA4:AA15,P4,R4,T4,T6,R6,P6,P8,R8,T8,T10,R10,P10,P12,R12,T12,T14,R14,P14,P16" _
                   ), .Range("R16,T16,T18,R18,P18,P20,R20")).SpecialCells(xlCellTypeConstants, 23)
            .Value = .Value + Sheets("Spins").Range("F2").End(xlToRight).Offset(7, 1).Value
        End With
    End With
    Last edited by Bernie Deitrick; 02-26-2014 at 03:14 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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. Macro to search column for blank cells & shift entire row right
    By BirdS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2014, 08:07 AM
  2. [SOLVED] Macro that searches a column for all the blank cells then highlights the row entire row.
    By TheOllie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2012, 09:41 AM
  3. how can avoid considering of blank cells in IF function
    By Lika in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-12-2006, 05:30 AM
  4. [SOLVED] Looping Macro That adds a blank row between different part #'s
    By fiero84 in forum Excel General
    Replies: 5
    Last Post: 03-25-2005, 03:06 AM
  5. [SOLVED] Number of different items in an entire column without knowing if some of the cells are blank
    By sam.fares@cmcsg.com in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-20-2005, 02:06 PM

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