IF statement that activates a macro

Polly27

New Member
Joined
Jul 6, 2009
Messages
4
Hi all,

I've got a question about an IF statement that should run a macro. In cell B2 there is a list of 1 tot 12 which resembles the months January till December. By default cell B2 = 1 and all files in the sheet are connected to the folder 'January' (e.g. if cell B2 = 1 then cell C1 = C:\January\[testfile.xls].!sheet1.C1).

If cell B2 = 2 then cell C1 should be connected to the folder February (e.g. C1 = C:\February\[testfile.xls].!sheet1.C1). And so on for March, April, etc.

I've made a macro which replaces all cells with "\January\" in the workpath by "\February\". This should be activated then if B2 = 2. But I guess and hope there's a smarter way of doing this.

Any help on this please?:confused:

Regards,

Polly
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
right-click your sheet tab and select 'view code'. paste the below:


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
If Target.Address = "$B$2" Then
    Range("C1").Formula = "='C:\" & MonthName(Target.Value) & "\[testfile.xls]Sheet1'!$C$1"
  Else
    'do nothing
End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,217
Members
448,876
Latest member
Solitario

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