Typing a formula with a macro.

amattey

New Member
Joined
Jul 18, 2011
Messages
46
Hello, I made a macro that types a formula and applies it to certain cells. However, I was wondering if it is possible to use an input box so when the macro is typing the formula we can get it to type the formula in the sheet we want but same cell. I have attached the code below. Will appreciate the help. The P in the formula I want it to be whatever we type in the input box. Thanks

Code:
Dim P As String
    
    P = InputBox("Enter Last Month's Sheet Name")
    Sheets(Format(Now(), "mmmm, yyyy")).Activate
    Range("I7").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-3]=P!RC[-3],VLOOKUP(RC[-3],P!C6:C9,4,FALSE),"""")"
    Range("I8").Select
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
try:

Code:
Dim P As String
    
    P = InputBox("Enter Last Month's Sheet Name")
    Sheets(Format(Now(), "mmmm, yyyy")).Activate
    Range("I7").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-3]=" & P & "!RC[-3],VLOOKUP(RC[-3]," & P & "!C6:C9,4,FALSE),"""")"
    Range("I8").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

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