lundi 11 janvier 2016

Excel 2013, searching for partial text in one cell and overwriting adjacent cell if condition is met

Please bare with me - it's my first post/question ever :)


I need to write a macro.

I've got a workbook with ~ 30000 rows (changes daily).

  1. I need to search for expression "TRADE" within the strings in cells from column(A)

  2. If string inside the cell contain expression TRADE I need to change string in relevant cell in column(B) (the same row) to expression "TRADEIN"

  3. If condition is not met relevant cells from column(B) need to stay unchanged


What have I learned so far:

Formula =IF(ISNUMBER(FIND("TRADE", A1 )), 1, 2) changes adjacent cell value accordingly ONLY if placed directly inside cell and copied down in Excel.

Problems starts when I try to have string as an outcome

Formula: =IF(ISNUMBER(FIND("TRADE", A1 )), "TRADEIN", "") won't work ->error

Formula: =IF(ISNUMBER(FIND("TRADE", A1 )), ""TRADEIN"", "") won't work ->error


Then any attempts to make my macro insert more complex formulas into cells from VBA failed i.e.:

Below works fine:

For i=1 to i=NumberOfRows

ActiveSheet.Cells(i, 2).Formula = "= 2+2"

next i


Below won't work (again, formula works if placed in the cell directly):

For i=1 to i=NumberOfRows

ActiveSheet.Cells(i, 2).Formula = "=IF(ISNUMBER(FIND("TRADE", (i, 1)), 1, 2)"

next i


I think there's no point in listing all my failed attempts to make it work so far (loads of useless lines to read I presume) but by all means - correct me if I'm wrong.

Please help. I can't find solution as specific as my task and have got problems altering some found online whilst other won't work for me at all. Perhaps don't exactly know how to ask for what I need in the most effective way. Be very basic and try not to miss out any declarations from proposed modules/subs if you can - I'm not yet confident when it comes to using and creating objects and methods outside of a few examples I followed, or choosing/using the right type of variables with compatible methods/functions etc.

Lastly - please forgive my English - I tried to make myself as clear as I can :)


Thank You in advance

Aucun commentaire:

Enregistrer un commentaire