How do I change the value in an Excel table cell without specifying a cell reference in VBA

volksdrohne

For example, in the following code, I look up a value from a table, increment the value, the write the new value back to the table. Right now, the value is written back to the table based on the cell name (i.e. "b5"). This all falls apart if the user sorts the table or adds/deletes and rows above it. What I would like to do is determine the name of the cell that the value was loaded from at the time of the lookup so that the new value can be put back in the same place.

 '*** Lookup last DEWR number from Properties Page ***
    intDEWRNum = Application.WorksheetFunction.VLookup( _
    "Current DEWR", Worksheets("Properties").ListObjects("propertiesTable").Range, 2, False)

    If intDEWRNum < 1 Then
        intDEWRNum = 1      ' If DEWR field is blank then this is the first DEWR.
    Else
        intDEWRNum = intDEWRNum + 1 ' Increment DEWR field
    End If

    Worksheets("Properties").Range("b5").Value = intDEWRNum
                               '^ This is what I want to avoid.***********


    newSheet.Name = "DEWR " & Str(intDEWRNum)   ' Name new worksheet with new DEWR number

    ActiveSheet.Range("j6").Value = Str(intDEWRNum)   ' Insert current DEWR number into sheet
Tim Williams
Dim f as Range

Set f = Worksheets("Properties").ListObjects("propertiesTable"). _
        Range.Columns(1).Find("Current DEWR",lookin:=xlvalues, lookat:=xlwhole)

If not f is nothing then
    intDEWRNum = f.offset(0,1).Value

    If intDEWRNum < 1 Then
        intDEWRNum = 1      ' If DEWR field is blank then this is the first DEWR.
    Else
        intDEWRNum = intDEWRNum + 1 ' Increment DEWR field
    End If

    f.offset(0,1).Value= intDEWRNum

    'etc....

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I change the value in an Excel table cell without specifying a cell reference in VBA

From Dev

How do I reference a cell in an Excel data table without using the cell coordinates?

From Dev

How do I change the value of a cell based on the position of a team in a table?

From Dev

Excel VBA: How to paste a value in the first Cell of the last row of a table?

From Dev

How do I convert a reference cell to a string in Excel?

From Dev

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

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

How do I get the Cell value in Excel using an environmental variable for a VBA If statement

From Dev

How to change cell reference style in Excel Online?

From Dev

How can I delete every cell with a specific value in excel vba?

From Dev

How can I delete every cell with a specific value in excel vba?

From Dev

how do I get a cell's location as a range in excel vba?

From Dev

How do I insert MergeField into specific table cell with VBA?

From Dev

How do I change the text of a cell without changing the formula?

From Dev

How do I change an HTML table cell value by a dynamically added button in each row

From Dev

EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within)

From Dev

How do I change the height of a table cell that has already loaded?

From Dev

DATA Table ... How to change the Color of cell as per the Cell Value Of Table

From Dev

Excel VBA: How do I PasteSpecial into same row of Cell location after Cell is changed?

From Dev

Excel VBA: How do I PasteSpecial into same row of Cell location after Cell is changed?

From Dev

How to change background color of cell based on other cell value by VBA

From Dev

VBA : How to change the cell's value in a function?

From Dev

How do I make Excel cell contents show a different value

From Dev

How to validate a cell value in excel VBA

From Dev

How can I make a cell in Excel to change colour according to the value of other cell?

From Dev

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

From Dev

How change cell table color in php based on cell value?

From Dev

How change cell table color in php based on cell value?

Related Related

  1. 1

    How do I change the value in an Excel table cell without specifying a cell reference in VBA

  2. 2

    How do I reference a cell in an Excel data table without using the cell coordinates?

  3. 3

    How do I change the value of a cell based on the position of a team in a table?

  4. 4

    Excel VBA: How to paste a value in the first Cell of the last row of a table?

  5. 5

    How do I convert a reference cell to a string in Excel?

  6. 6

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

  7. 7

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

  8. 8

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

  9. 9

    How do I get the Cell value in Excel using an environmental variable for a VBA If statement

  10. 10

    How to change cell reference style in Excel Online?

  11. 11

    How can I delete every cell with a specific value in excel vba?

  12. 12

    How can I delete every cell with a specific value in excel vba?

  13. 13

    how do I get a cell's location as a range in excel vba?

  14. 14

    How do I insert MergeField into specific table cell with VBA?

  15. 15

    How do I change the text of a cell without changing the formula?

  16. 16

    How do I change an HTML table cell value by a dynamically added button in each row

  17. 17

    EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within)

  18. 18

    How do I change the height of a table cell that has already loaded?

  19. 19

    DATA Table ... How to change the Color of cell as per the Cell Value Of Table

  20. 20

    Excel VBA: How do I PasteSpecial into same row of Cell location after Cell is changed?

  21. 21

    Excel VBA: How do I PasteSpecial into same row of Cell location after Cell is changed?

  22. 22

    How to change background color of cell based on other cell value by VBA

  23. 23

    VBA : How to change the cell's value in a function?

  24. 24

    How do I make Excel cell contents show a different value

  25. 25

    How to validate a cell value in excel VBA

  26. 26

    How can I make a cell in Excel to change colour according to the value of other cell?

  27. 27

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

  28. 28

    How change cell table color in php based on cell value?

  29. 29

    How change cell table color in php based on cell value?

HotTag

Archive