Results 1 to 6 of 6

Thread: VBA - Command Button to Multiply Value In Cell in Last Updated Column

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    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
    Attached Files Attached Files
    Last edited by DocAElstein; 04-10-2020 at 03:36 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 0
    Last Post: 03-29-2018, 05:38 PM
  2. Save and change data in the same command button
    By marreco in forum Excel Help
    Replies: 4
    Last Post: 12-24-2013, 07:30 PM
  3. Replies: 10
    Last Post: 10-17-2013, 07:36 PM
  4. Replies: 2
    Last Post: 04-17-2013, 11:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •