I have a simple formula of multiplication
For ex: =A1*60.
I would like to know how can i convert this simple formula into a macro coding.
Can any one help me.
I have a simple formula of multiplication
For ex: =A1*60.
I would like to know how can i convert this simple formula into a macro coding.
Can any one help me.
Last edited by Saky; 11-30-2010 at 12:28 PM.
Hi Saky,
Using VBA, if you wanted your above formula in A2 the code would be:
Range("A2").Formula = "= A1 * 60"
hth
One test is worth a thousand opinions.
Click the * Add Reputation below to say thanks.
Hi Marvin,
Thanks for your quick revert!!!!
If i need this macro to function when i change the cursor from one cell to the other...i meant to say if i want to do it change event how do i need to start the VBA coding.
Is that correct???![]()
Private Sub Worksheet_Change(ByVal Target As Range) Range("A2").Formula = "= A1 * 60" End sub
Last edited by Saky; 11-29-2010 at 10:39 AM.
One example
What are you really wanting to do?![]()
Range("A2") = Range("A1") * 60
If you need any more information, please feel free to ask.
However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....
Also
اس کی مدد کرتا ہے اگر
شکریہ کہنے کے لئے سٹار کلک کریں
If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.
Please wrap your code in code tags, before the moderators get you...
Forum rules
3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.
You need to use the Worksheet SelectionChange event
An example of what you are trying to do would not go amiss.
Cheers.
oops i am sorry...i have done it...Thanks for saving me
Marcol, can you give me tell me how to use the Worksheet SelectionChange event.
If possible can you give me the exact code for the above formula using change event..
thanks a ton...
Reading your question again, it might be that either event change could solve your problem.
If we have an example workbook to work with then your problem will be quickly solved.
Show the range you want to apply the rule to, and the destination of the results.
Without a workbook we are only guessing.
Sorry for troubling you without giving the sample workbook Marcol.
I have attached a workbook.
In that if i enter values in say A3, then C3 should give me the result by multiplying the value into 60. and the same way if i enter the value in B3 then C4 sholud show me the result.
Can you help me to do this using VBA coding. i want this to happen till the range A20 to D20
Last edited by Paul; 11-30-2010 at 03:33 AM. Reason: Removed quote of full post, unnecessary.
Try this in the worksheet module
![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim isect As Range If Target.Cells.Count > 1 Then Exit Sub On Error GoTo ResetApplication Application.EnableEvents = False Set isect = Intersect(Target, Range("A3:A20")) If Not isect Is Nothing Then If Target <> "" Then Range("C" & Target.Row) = Target * 60 Else Range("C" & Target.Row) = "" End If End If ResetApplication: Err.Clear On Error GoTo 0 Application.EnableEvents = True Set isect = Nothing End Sub
Hope this helps
Friend, Thanks for your great help...This code is awesome it works great!!!!
But in my original excel instead of column A,B and C,D i have the columns as Col O,P and Q,R. So i just copy and pasted the coding and made some changes as below. But it is not working in it...Can you clarify where am i going wrong...
![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim isect As Range If Target.Cells.Count > 1 Then Exit Sub On Error GoTo ResetApplication Application.EnableEvents = False Set isect = Intersect(Target, Range("O3:O20")) If Not isect Is Nothing Then If Target <> "" Then Range("Q" & Target.Row) = Target * 60 Else Range("Q" & Target.Row) = "" End If End If ResetApplication: Err.Clear On Error GoTo 0 Application.EnableEvents = True Set isect = Nothing End Sub
Last edited by Paul; 11-30-2010 at 03:33 AM. Reason: Removed quote of full post, unnecessary.
Seems to work for me
Marcol,
Its working in the attached excel in this thread...but when i paste the same coding in my original excel it is not working..
I have hereby attached my original excel...Can you kindly check and advice me where am i going wrong
Column M is where i will enter the value and i want the result in column O.
Thanks for your patience...
You already have code in the worksheet module for Sheets("Status") the new code must be added to that code.
You have added the code in a standard module, it will not work from there.
I'll look at it later, look back in a few hours, remember your time is 5:30 hrs ahead of us in the UK.
Am really sorry for disturbing you in a very early hours....I don't know that u r located in UK.
No problem you take ur time and reply me...Now the time here is 3.30(noon).. I will be office till 9.30 PM(night) that will be 4 clock eve in UK. If possible you could reply me during that time it would be great..
You are so kind Marcol....Thanks for your help so far......
What version of Excel are you using?
Your file is 2003 but some conditions you have applied will not work in that version, you will need 2007 or later.
Do you need this workbook to work in 2003 and later?
Please update your profile to indicate which version of Excel you are using.
Marcol,
I am using Microsoft Office Excel 2003. I do not have any advanced version. I have updated the same in my profile.
I want this macro to function in Excel 2003. Can you kindly help.
Hi Marcol,
Any luck on this? Can we write the coding in Module2 and sheet2 tabs and can we use the change and worksheet activate events to fire the code.
As i did in my attached excel...Is that can be done???
Try this version of your workbook
1/. I have added a sheet "Lookups" and created dynamic named lists for each catagory you require for data validation, you can add /change/ delete any data in these lists.
Don't leave blank cells in these lists, if you want to delete an item use Delete Cells > Shift Cells Up
This makes the code in the worksheet change event much simpler.
This Lookup sheet can be hidden.
2/. I have changed you macro "Test" to "TestStatus" and moved it's trigger to the ThisWorkbook module, Workbook_Open event, and also called it in the Worksheet_Change event (Sheets("Status"))
I have assumed that each project will have an SI number and the last row in this column ("A") determines the number of rows to check the status as changes are made.
3/, 2003 can only handle three conditional formats, I have changed the base colour of Column J to allow the colour codes you require
Try changing the data in Column E to test the drop-Down in F
Try changing dates in columns H K & L to se the result in column I, you probably don't need the validation in column I, but I have left it just in case.
Hope this helps
Marcol,
Thanks is a very simple word for your great help!!!!! Really this excel works great and satisfy my expectation.
Marcol am really sorry for troubling you so long to make you do my homework..
Really you helped me a lot.. Thanks a million again for your time and help!!!
Happy to help.
You would do well to have a look as this link on Dynamic Named Lists
http://www.cpearson.com/Excel/excelF.htm#DynamicRanges
and follow the links from there
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks