+ Reply to Thread
Results 1 to 6 of 6

Condition based replacements of Cells with other values

Hybrid View

vamshi57 Condition based replacements... 09-30-2010, 04:46 PM
DonkeyOte Re: Condition based... 09-30-2010, 04:52 PM
vamshi57 Re: Condition based... 09-30-2010, 05:04 PM
DonkeyOte Re: Condition based... 09-30-2010, 05:19 PM
DonkeyOte Re: Condition based... 09-30-2010, 05:23 PM
vamshi57 Re: Condition based... 09-30-2010, 06:15 PM
  1. #1
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Condition based replacements of Cells with other values

    Not sure why you need to replace - could not just reverse the logic of your summary calcs ?

    If you need to replace then it would be best to first run an Edit -> Replace for each value (1 to 5 [ignoring 3]) replacing the digit with a separate character: eg 1 to @ and 2 to ^ etc...

    Once complete run a subsequent Edit -> Replace for each value converting @ to 5, ^ to 4 etc...

    (avoid using *, ~, ? characters)
    Last edited by DonkeyOte; 09-30-2010 at 04:55 PM. Reason: edit: revised based on wildcards !

  2. #2
    Registered User
    Join Date
    11-07-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: Condition based replacements of Cells with other values

    This is exactly what I have been doing .. but its more of a manual work as I need to do 8 iterations to complete the cycle . Once I get the data I'm atleast spending 4-5 min replacing the cells before I create the pivots out of it .

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Condition based replacements of Cells with other values

    You can replicate the process in Code, in basic terms:

    Sub Example()
        Dim vFW As Variant, vRW As Variant
        Dim lngR As Long
        On Error GoTo ExitPoint
        Application.ScreenUpdating = False
        vFW = Array(1, 2, 4, 5)
        vRW = Array("^", "@", "[", "]")
        For lngR = LBound(vFW) To UBound(vFW) Step 1
            With Selection
                .Replace vFW(lngR), vRW(lngR)
            End With
        Next lngR
        For lngR = LBound(vFW) To UBound(vFW) Step 1
            With Selection
                .Replace vRW(lngR), vFW(UBound(vFW) - lngR)
            End With
        Next lngR
    ExitPoint:
        Application.ScreenUpdating = True  
    End Sub
    above is geared to run against the active selection at run-time

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Condition based replacements of Cells with other values

    A quicker alternative might be:

    Sub Example()
        Dim rngArea As Range
        For Each rngArea In Selection.Areas
            With rngArea
                .Value = .Parent.Evaluate("IF(ISNUMBER(" & .Address & "),1+5-" & .Address & ",REPT(" & .Address & ",1))")
            End With
        Next rngArea
    End Sub

  5. #5
    Registered User
    Join Date
    11-07-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: Condition based replacements of Cells with other values

    Amazing .. This is exactly what I was looking for . Thank you so much .

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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