Click here to Skip to main content
15,850,265 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am currently working on an Excel sheet where I want to enter a row number into a cell, and on the click of a button, excel will locate the row and then run a macro to update a cell.

May I know the behind code for this or any examples to get me started?


Update:
When a user clicks on a cell in a range, the whole row of the table will be selected, and on button click (linked to macro UpdateFormula) will be run to insert the .Formula into the cells.

VB
Sub UpdateFormula()
Range(Cells(Selection.Row, 18), Cells(Selection.Row, 24)).Select
Range("anchor_variable").Formula = "=Anchor1"
Range("table_variable").Formula = "=base_point+short_end_increment*(base_year-R$15)"
End Sub

The code enables me to insert the formula into the whole table but not into the cells that I have selected specifically.

What I want is to insert the formula only to the row that I am clicking on

Thank You :)
Posted
Updated 26-May-15 22:52pm
v4
Comments
Maciej Los 27-May-15 2:14am    
What have you tried? Where are you stuck?
You did not specify what kind of issue do you have. I'd suggest to update question (use "Improve question" widget). At this moment this is not a question, it's a code request.
Member 11667493 27-May-15 3:14am    
I have updated the question, thank you!

 
Share this answer
 
Comments
Maciej Los 27-May-15 2:15am    
Good suggestion ;)
+5!
Mathew Soji 27-May-15 2:38am    
Thank you
Use Worksheet.SelectionChange event[^], for example:
VB
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
    With Target
        .Range("anchor_variable").Formula = "=Anchor1"
        .Range("table_variable").Formula = "=base_point+short_end_increment*(base_year-R$15)"
    End With
End Sub
 
Share this answer
 
Comments
Member 11667493 29-May-15 2:23am    
Thank you very much! :)
Maciej Los 29-May-15 2:44am    
You're very welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900