I have asked several questions in regards to data validation menu calling macros. I have come very close to solve my problems. However, when I apply my code on the worksheet, excel always print out the content of my last macro. My Code for the worksheet is as below:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$3" Then
On Error GoTo bm_Safe_Exit
Application.EnableEvents = False
Select Case Target.Value2
Case "ABCP"
Call Macro1
Case "Accounting Policy"
Call Macro2
Case "Audit Committee"
Call Macro3
Case "Auto"
Call Macro4
Case "Auto Issuer Floorplan"
Call Macro5
Case "Auto Issuers"
Call Macro6
Case "Board of Director"
Call Macro7
Case "Bondholder Communication WG"
Call Macro8
Case "Canada"
Call Macro9
Case "Canadian Market"
Call Macro10
Case Else
'Do Nothing
End Select
End If
bm_Safe_Exit: Application.EnableEvents = True End Sub
I have ten Macros, and the content is pretty much the same, only cell changes. And here is the code:
Sub Macro1()
Range("F2").Select
Selection.FormulaArray = _
"=IF(COUNTIF(Database!R2C35:R10000C35,Committees!R2C1)>=ROW(Committees!R2C:RC),INDEX(Database!R2C[-5]:R10000C[-5],SMALL(IF(Database!R2C35:R10000C35=Committees!R2C1,ROW(Database!R2C35:R10000C35)-ROW(Database!R2C35)+1),ROWS(Committees!R2C:RC))),"""")"
Selection.AutoFill Destination:=Range("F2:T2"), Type:=xlFillDefault
Range("F2:T2").Select
Selection.AutoFill Destination:=Range("F2:T5000")
Range("F2:T5000").Select
Sheets("Reports").Select
Range("F2").Select
Selection.FormulaArray = "=IF(ISERROR(Committees!RC),"""",Committees!RC)"
Selection.AutoFill Destination:=Range("F2:T2"), Type:=xlFillDefault
Range("F2:T2").Select
Selection.AutoFill Destination:=Range("F2:T5000")
Range("F2:T5000").Select
Range("E2").Select
End Sub
When I run macro in VBA, it also notifies me that the AutoFill Range failed.
Please help correct the code, thanks!
.Activate \ .Select
, as it can cause headaches for sure, especially when using multiple worksheets. Also, which macro is throwing the error, the Worksheet_Change event, orMacro 1
? What line and what error does it occur on? – BruceWayne.Select
. I'll add an answer which will show you yourMacro 1
without.Select
and see if that helps any. – BruceWayne