VBA query

CVN55

New Member
Joined
Jun 14, 2017
Messages
25
Hi - someone on this forum wrote below for me and it works perfectly, but I need the "M3" in line 3 to be a cell in another workbook ie. Sheet 2 cell C29, how can I change this please?

Thank you,
Catherine

Private Sub Worksheet_Change(ByVal Target As Range)
Dim nStr As String
If Target.Address(0, 0) = "M3" Then
Select Case Target.Value
Case "Portfolio", "Portfolio status not yet known": nStr = "Research, Service Support, Excess Treatment, Standard Treatment"
Case "NonPortfolio": nStr = "Research"
End Select
With Range("K8:K14, K21:K26, K34:K40, K48:K51, K60:K64, K74:K77").Validation
.Delete
.Add Type:=xlValidateList, Formula1:=nStr
End With
End If
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Catherine,

You say "but I need the "M3" in line 3 to be a cell in another workbook ie. Sheet 2 cell C29". Are you really meaning another workbook/file or just another worksheet in the same workbook. Either way, can you provide the name of the other workbook?
 
Upvote 0
@CVN55, if you are using it as a Worksheet_Change event then you need to put the code in the Sheet 2 module and change

Code:
If Target.Address(0, 0) = "M3" Then
to
Code:
If Target.Address(0, 0) = "C29" Then

and

Code:
With Range("K8:K14, K21:K26, K34:K40, K48:K51, K60:K64, K74:K77").Validation

to

Code:
With Sheets("Sheet 1").Range("K8:K14, K21:K26, K34:K40, K48:K51, K60:K64, K74:K77").Validation

Please note that I have put the space in Sheet 1 as you have written Sheet 2 with the space but the default is Sheet2 without the space and so change as necessary.
 
Upvote 0
So that does mean I will have 1 code in each workbook, each referring to the other workbook? Thank you...
 
Upvote 0
Why are you talking WorkBooks again? If mean WorkSheets then yes you are using WorkSheet_Change code so it needs to be in each sheet.

You are probably better off by the sound of it using ThisWorkbook event code and in particular looking at Workbook_SheetChange.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

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