Hello ollie.
Welcome to ExcelFox
I’ll answer what I understand from your question first, then we can take it further later if you still need /want any further help. I will keep it as simple as possible initially since you are new to VBA
( Your title and your description seem a bit contradictory, and I am not sure what worksheet is being updated, but I will give you/ us something to start with. … )
The uploaded workbook has 3 worksheets, Sht1 , Sht2 and GlobySht.
In the code module of worksheet 1 is an “event macro” that starts when any cells value is changed in the first worksheet.
That simple macro stores the address of the last changed cell. ( Typically we call the variable used a global variable. At least programmes do. I am not really a programmer so I did it a bit differently and store the address on the first cell of the third worksheet instead )
The coding behind the Command Button then uses that stored address to do the following: For example: If the last cell changed in the first worksheet was in row 3 ( of the first worksheet), then the value in cell G3 of the second worksheet will be multiplied by 10
Alan
Code:Option Explicit ' http://www.excelfox.com/forum/showthread.php/2452-VBA-Command-Button-to-Multiply-Value-In-Cell-in-Last-Updated-Column Public Globy As String ' Global variable Private Sub Worksheet_Change(ByVal Target As Range) ' Target is pre Set by Excel to be the range changed ' Let Globy = Target.Address Let Worksheets.Item(3).Range("A1").Value = Target.Address ' store the address of the changed cell in the third worksheet's first cell End Sub Private Sub CommandButton1_Click() ' coding behind the command button Worksheets.Item(2).Activate ' I don't need to do this. it is just so i can see what is changed Dim Rw As String ' Let Rw = Split(Tabelle1.Globy, "$", 3, vbBinaryCompare)(2) Let Rw = Split(Worksheets.Item(3).Range("A1").Value, "$", 3, vbBinaryCompare)(2) ' We have an address like $A$1 We split it into 3 bits using the $ as the seperator. So we have like "" "A" "1" The indicies are 0 1 2 for the array of things returned from the split function 0 is empty 1 is the letter A 2 is the number 1 Let Worksheets.Item(2).Range("G" & Rw & "").Value = Worksheets.Item(2).Range("G" & Rw & "").Value * 10 End Sub




Reply With Quote
Bookmarks