Results 1 to 3 of 3

Thread: Well versed in formulas but NOT VBA Code - Help a noob!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    I agree - I think you were approaching the problem from the WS POV

    From a VBA approach, maybe something like this.



    Option Explicit
    'If the Description contains 1 of 4 things (******776, ******732, Vanguard, or Robinhood) AND the Type is a Withdrawal,
    'I want the value under Amount to go from a negative value to a positive value and
    'I want the Type to go from Withdrawal to Deposit. The number will only ever need to go from negative to positive.
    'The reason these need to be If/AND type statements is because even though the row contains the key word Robinhood,
    'there are both withdrawals and deposits that contain the same word.
    'So I wouldn't want to make those positive numbers negative by mistake.
    
    Const colAmt As Long = 1
    Const colType As Long = 2
    Const colDesc As Long = 3
    
    Sub ManipulateData()
        Dim rData As Range, rRow As Range
        
        Set rData = ActiveSheet.Cells(1, 1).CurrentRegion
        
        Application.ScreenUpdating = False
        
        For Each rRow In rData.Rows
            With rRow
                Select Case .Cells(colDesc).Value
                    Case "******776", "******732", "Vanguard", "Robinhood"
                        If .Cells(colType).Value = "Withdrawal" Then
                            .Cells(colAmt).Value = -1# * .Cells(colAmt).Value
                            .Cells(colType).Value = "Deposit"                                    '!!!! missed this
                        End If
                End Select
            End With
        Next
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by Paul_Hossler; 08-17-2016 at 01:11 PM. Reason: missed a change
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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