+ Reply to Thread
Results 1 to 5 of 5

If statement, Find Replace, Concatenate in VBA code

  1. #1
    Registered User
    Join Date
    01-13-2005
    Location
    lebanon
    Posts
    3

    Post If statement, Find Replace, Concatenate in VBA code

    I have an excel statement of account with transaction type found in column I
    I tried to work with if statements and vlookup but guess i am missing something or my knowledge is not helping me. I can do the simple formula but i want it incorporated into macros so i can use it with other excel files

    I have many transaction types but for a few of them i want to change them according to the info in other cells
    All the data in the column i mentioned are text and not numbers

    This is what i want to do:

    1- For all transaction type = incoming swift i want to replace it with:"incoming swift" & the value in column Y & the value in column Z

    2- For all transaction type = outgoing swift i want to replace it with: "outgoing swift" & the value in column V & the value in column W

    3-For all transaction type = In Acc , where the values in column AD is not equal to value in AF then replace transaction type to : "Transfer from" & the value of column AD & for the false statement to replace transaction type to: "Between accounts"

    4-For all transaction type = Out Acc , where the values in column AD is not equal to value in AF then replace transaction type to : "Transfer from" & the value of column AF & for the false statement to replace transaction type to: "Between accounts"

    I suupose i need to use : =If(AND, ,,,) but i cant seem to let to manage the concatenate the cells in the values i want

    I have several other transaction types i want to replace but if i know how to start i can manage the rest

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: If statement, Find Replace, Concatenate in VBA code

    What do you mean "replace transaction type"? Do you mean you want to physically change the data in the cell that currently says "incoming swift" with a formula? What is wrong with adding another column and entering the formula? You would not need VBA if you did it that way.

    Regarding working out the formulae, the best thing is to do it one step at a time. Put each part of the formula in a separate cell, then once you have the final result in one of the cells, you go back and cut and past the parts of the formula from each cell into the last cell. Hope that makes sense.

  3. #3
    Registered User
    Join Date
    01-13-2005
    Location
    lebanon
    Posts
    3

    Re: If statement, Find Replace, Concatenate in VBA code

    Thanks for your reply
    I dont want to add a column as it would change other formulas for me plus i need to keep original data fields and column as is. I managed to find a solution for the wire transfer with this code (provided graciously from someone). It works well as long as i have it on the workbook i am working on, i want the vb codes on a seperate workbook and then open any file i want and run the code

    ---------------------------
    Sub almouchie()
    Dim lr As Long
    Dim rcell As Range

    lr = Cells(Rows.Count, 1).End(xlUp).Row

    For Each rcell In Range("I2:I" & lr)

    Select Case rcell.Value

    Case Is = "incoming swift"

    rcell.Value = rcell.Value & rcell.Offset(, 16).Value & rcell.Offset(, 17).Value

    Case Is = "outgoing swift"

    rcell.Value = rcell.Value & rcell.Offset(, 13).Value & rcell.Offset(, 14).


    End Select

    Next rcell


    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: If statement, Find Replace, Concatenate in VBA code

    Turn on the macro recorder and select "personal macro book" as the place to store the macro
    record a couple of random steps. Just selecting a cell will do
    Stop the recorder and go and edit the code. It will be in module 1 in the personal workbook.

    Paste your macro (from your post above) in this new workbook, then exit excel and save he personal workbook when prompted. Your macro will then always be available. You can add as many macros to this book in the future

  5. #5
    Registered User
    Join Date
    01-13-2005
    Location
    lebanon
    Posts
    3

    Re: If statement, Find Replace, Concatenate in VBA code

    I can manage to save it in another workbook where i have my other vb codes
    I added that to be able to read the excel file i am using but still not working

    ---------------------------
    Sub almouchie()
    Dim lr As Long
    Dim rcell As Range

    Windows("myworkbook").activate
    Sheets("master").select

    lr = Cells(Rows.Count, 1).End(xlUp).Row

    For Each rcell In Range("I2:I" & lr)

    Select Case rcell.Value

    Case Is = "incoming swift"

    rcell.Value = rcell.Value & rcell.Offset(, 16).Value & rcell.Offset(, 17).Value

    Case Is = "outgoing swift"

    rcell.Value = rcell.Value & rcell.Offset(, 13).Value & rcell.Offset(, 14).


    End Select

    Next rcell


    End Sub

+ 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