excel macro : Change cell value dependant on original cell value

r_j

When recording a macro, i want to change the current value of a cell to a new value dependant on the original value. not set it to a "recorded" value.

Example : value in cell needs to change from .1234 (text) to 0,1234 (number). And .56789 to 0,56789

My work method is:

record macro
"F2" : to change value,
"home" : go to beginning,
"del",
"del",
"0",
",",
"return",
stop record macro

but when i use the macro on other fields, the value is changed to 0,1234 even when original value is .5678 for example.

Takedasama

This can be done in VBA but the most simple solution (if all your values begin with ".") is to use the built in "Text to Columns" Excel option (by simply selecting your entire column then ALT+A, +E, +F). If this has to be done with VBA please tell. Hope this alone helps.

Edit I've wrote this code to solve your problem (based on the rule of the cell values are starting with "." and then switching to numbers is made by adding a "0" to the initial text). Then "number" format is picked up by Excel as implicit format.

Sub ChangeFormat()
For i = 1 To 2 'This is the row index (it's now set to the 1st 2 rows.)
    For j = 1 To 2 'This is the column Index (i.e. column 2 is B, 1 is A, etc.) (it's now set to the A and B columns)
        If Left(ActiveSheet.Cells(i, j), 1) = "." Then
            ActiveSheet.Cells(i, j).Value = "0" & ActiveSheet.Cells(i, j).Value
        End If
    Next j
Next i
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change Chart Colour Dependant On Cell Value

From Dev

Excel cell value update macro

From Dev

Cell Value Change Event and Running a Continuous Macro

From Dev

cell value change not getting captured in vba macro

From Dev

Excel macro to group rows based on a cell value

From Dev

excel macro to add value from cell to a table

From Dev

Excel Macro - Remove rows and then relabel a cell value

From Dev

Cancel button in inputbox no change of value in excel cell

From Dev

How to change a formula according to cell value in excel?

From Dev

Excel VBA put a value in cell A and cell B will change automatically

From Dev

Change Value of Excel Cell when another cell contains specific character

From Dev

Display change in value of a cell in adjacent cell using excel VBA

From Dev

Excel VBA put a value in cell A and cell B will change automatically

From Dev

Change value in a cell based on value in another cell

From Dev

Can I add a macro to change the value of a cell in sheet 2 based on increasing the value of a cell in sheet 1

From Dev

Change Cell Value if There is Overflow

From Dev

Cell value change with Month

From Dev

Change value of cell in Javascript

From Dev

Insert value of Excel cell as a SQL query parameter in macro

From Dev

excel macro - how to delete rows based on a cell value

From Dev

Excel macro, search by row return next cell's value

From Dev

Excel - Restrict the value of a cell

From Dev

Empty value in Excel cell?

From Dev

Cell value format in Excel

From Dev

How to track the changes in a cell value by comparing to the original template in MS Excel?

From Dev

Excel Formula: Reference a cells value whilst maintaining original cell reference

From Dev

Excel copy cell value to another cell if cell value changes

From Dev

Excel copy cell value to another cell if cell value changes

From Dev

Excel VBA Macro - find text in cell one, replace value in adjacent cell

Related Related

  1. 1

    Change Chart Colour Dependant On Cell Value

  2. 2

    Excel cell value update macro

  3. 3

    Cell Value Change Event and Running a Continuous Macro

  4. 4

    cell value change not getting captured in vba macro

  5. 5

    Excel macro to group rows based on a cell value

  6. 6

    excel macro to add value from cell to a table

  7. 7

    Excel Macro - Remove rows and then relabel a cell value

  8. 8

    Cancel button in inputbox no change of value in excel cell

  9. 9

    How to change a formula according to cell value in excel?

  10. 10

    Excel VBA put a value in cell A and cell B will change automatically

  11. 11

    Change Value of Excel Cell when another cell contains specific character

  12. 12

    Display change in value of a cell in adjacent cell using excel VBA

  13. 13

    Excel VBA put a value in cell A and cell B will change automatically

  14. 14

    Change value in a cell based on value in another cell

  15. 15

    Can I add a macro to change the value of a cell in sheet 2 based on increasing the value of a cell in sheet 1

  16. 16

    Change Cell Value if There is Overflow

  17. 17

    Cell value change with Month

  18. 18

    Change value of cell in Javascript

  19. 19

    Insert value of Excel cell as a SQL query parameter in macro

  20. 20

    excel macro - how to delete rows based on a cell value

  21. 21

    Excel macro, search by row return next cell's value

  22. 22

    Excel - Restrict the value of a cell

  23. 23

    Empty value in Excel cell?

  24. 24

    Cell value format in Excel

  25. 25

    How to track the changes in a cell value by comparing to the original template in MS Excel?

  26. 26

    Excel Formula: Reference a cells value whilst maintaining original cell reference

  27. 27

    Excel copy cell value to another cell if cell value changes

  28. 28

    Excel copy cell value to another cell if cell value changes

  29. 29

    Excel VBA Macro - find text in cell one, replace value in adjacent cell

HotTag

Archive