paste formula with macro

Rajkiran557

New Member
Joined
Jun 21, 2014
Messages
10
Hi,

i need a macro to paste the below formula in a range for cells, however i need to select the cell reference with help of a input box because the value is not always in A2 and i also need to select the range where the formula has to be pasted

=IF(A2<=30,""0-30"",IF(A2<=60,""31-60"",IF(A2<=90,""61-90"",IF(A2<=120,""91-120"",""120+""))))

all i got was

Set UserRange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)


UserRange.Value = _
"=IF(A2<=30,""0-30"",IF(A2<=60,""31-60"",IF(A2<=90,""61-90"",IF(A2<=120,""91-120"",""120+""))))"


appreciate your help....:)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Ok, so what else doo you need...what you have will do the trick
Code:
Sub MM1()
Set UserRange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
UserRange.Formula = "=IF(A2<=30,""0-30"",IF(A2<=60,""31-60"",IF(A2<=90,""61-90"",IF(A2<=120,""91-120"",""120+""))))"
End Sub
 
Upvote 0
Ok, so what else doo you need...what you have will do the trick
Code:
Sub MM1()
Set UserRange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
UserRange.Formula = "=IF(A2<=30,""0-30"",IF(A2<=60,""31-60"",IF(A2<=90,""61-90"",IF(A2<=120,""91-120"",""120+""))))"
End Sub

yeah with that i am able to paste the formula but i need to select the cell reference in the formula.. that is i don't want the " A2 " to be fixed i need to select it before i paste the formula.. 'excuse me I am not familiar with the technical words' sorry if a got you confused.

Thank in advance..
 
Upvote 0
Okay, now I get it....maybe this way then
Code:
Sub MM1()
sr = Application.InputBox(Prompt:="Please Select First cell", Title:="Range Select", Type:=8).Address(False, False)
er = Application.InputBox(Prompt:="Please Select Last cell", Title:="Range Select", Type:=8).Address(False, False)
Range(sr & ":" & er).Formula = "=IF(" & sr & "<=30,""0-30"",IF(" & sr & "<=60,""31-60"",IF(" & sr & "<=90,""61-90"",IF(" & sr & "<=120,""91-120"",""120+""))))"
End Sub
 
Upvote 0
Okay, now I get it....maybe this way then
Code:
Sub MM1()
sr = Application.InputBox(Prompt:="Please Select First cell", Title:="Range Select", Type:=8).Address(False, False)
er = Application.InputBox(Prompt:="Please Select Last cell", Title:="Range Select", Type:=8).Address(False, False)
Range(sr & ":" & er).Formula = "=IF(" & sr & "<=30,""0-30"",IF(" & sr & "<=60,""31-60"",IF(" & sr & "<=90,""61-90"",IF(" & sr & "<=120,""91-120"",""120+""))))"
End Sub


Thanks for that Mike

But i think i am missing something when i try to run the macro it just goes blank on me nothing happens.. :(

actually i don't see the run option itself
 
Upvote 0
Where are you putting the code ??
Try pasting it in a Standard module or "this Workbook" module
 
Upvote 0
Ok, when you ALT + F8, what is selected in the
"Macros in:" box down the bottom ??
It is a Macro enabled workbook, isn't it ?

There is no reason it won't show
 
Upvote 0
I tried the code as posted and got an error saying it needed to reference a sheet. (Standard module)

Changed MM1 to XX_MM1 and it works fine for me.

MM1 is a cell reference, may be the problem...?

Regards,
Howard
 
Upvote 0
@ Hi Howard....that's odd....I always use MM1 as my sub names.....even in 2013 ....:confused:
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top