我想知道如何以标题为"适用于"的条件格式访问该列并输入我自己的条件.我已经包含了截图以供更好的参考.

我在条件格式中添加语法的代码是,
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=" & c.Address & "=TRUE"
.
.
.
End With
Run Code Online (Sandbox Code Playgroud)
我相信应该在那里添加代码,但我找不到正确的语法.
更新:
我更新了我的代码,看起来像这样,
With Range(Cells(c.Row, "B"), Cells(c.Row, "N"))
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=" & c.Address
.FormatConditions(1).Interior.ColorIndex = 15 'change for other color when ticked
End With
Run Code Online (Sandbox Code Playgroud)
这基本上会使特定范围的行与我放置复选框的位置相关,其背景颜色会发生变化.复选框位置由c.Address表示,其中'c'包含我选中放置复选框的单元格的位置.
我已经定义了自己的Excel函数(称为ADXExcelFunctionDeescriptor).方法存根如下所示:
public static object ExecuteMyFunction(object values, object tagName)
{ // Some code here }
Run Code Online (Sandbox Code Playgroud)
该方法接收一个double值数组和一个名为name的字符串.
在设计视图中,我的ADXExcelFunctionDeescriptor如下所示:

我通过以下代码行调用并设置函数:
var formula = string.Format(@"={0}({1};{2})", Temp.FORMULA_NAME, this.DataRangeTextBox.Text, tagCaption);
resultRange.set_Value(Type.Missing, formula);
resultRange.Formula = resultRange.Value;
Run Code Online (Sandbox Code Playgroud)
这将导致异常!例外情况如下:
System.Runtime.InteropServices.COMException occurred
HResult=-2146827284
Message=Ausnahme von HRESULT: 0x800A03EC
Source=""
ErrorCode=-2146827284
StackTrace:
bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Microsoft.Office.Interop.Excel.Range.set_Value(Object RangeValueDataType, Object )
bei bb.ExcelToolbar.Controls.bbControl.ApplyFormula(Object sender, EventArgs e) in c:\xx\yy\zz\bb\bb.ExcelToolbar\Controls\bbControlcs:Zeile 88.
InnerException:
Run Code Online (Sandbox Code Playgroud)
此外,如果我没有传递tagName参数,该函数将返回一个没有任何异常或错误的结果.
var formula = string.Format(@"={0}({1})", Temp.FORMULA_NAME, this.DataRangeTextBox.Text, tagCaption);
resultRange.set_Value(Type.Missing, formula);
resultRange.Formula …Run Code Online (Sandbox Code Playgroud) 我最近遇到过这种情况,如果有更简单的方法可以做到这一点,我只是很好奇......
With Activeworkbook
'Do Stuff
With .Sheets(1)
'More stuff Done
'...
'But now I need to refer to or pass the Sheet in the last With Statement
SomeFunctionAnswer = SomeFunction Activeworkbook.Sheets(1)
End With
'Yet more stuff Done
End With
Run Code Online (Sandbox Code Playgroud)
它是否必须完全写出来,或者是否有某种方式来表示它更容易/更清洁?也许有某种属性或方法可以为这个实例传递自己的东西?如何从更高的位置引用属性或方法?
SomeFunctionAnswer = SomeFunction .Self '???
'OR
SomeFunctionAnswer = SomeFunction .Parent.Name '???
Run Code Online (Sandbox Code Playgroud)
希望有道理......
在Rubberduck 2.0.11.2453中运行代码检查后,有4个Range引用被标记为:
成员'Range'隐式引用ActiveSheet
有问题的范围是指命名范围.是否有必要限定命名范围参考?
Private Sub RunORatio(ByVal TabNum As Integer)
Dim Start As Integer, Cat As Integer, iMth As Integer, CurrentRow As Integer, Report As Integer
Dim wsORatio As Worksheet, wsData As Worksheet, wsMacro As Worksheet
Dim sMap As String, Test As String
With ActiveWorkbook
Set wsMacro = .Worksheets("Macro")
Set wsORatio = .Worksheets("ORatio" & TabNum)
With wsORatio
sMap = "oratio" & TabNum & "map"
For CurrentRow = 1 To Range(sMap).Rows.Count '<---1 here
Test = Range(sMap).Cells(CurrentRow, 1) '<---1 Here
Set wsData …Run Code Online (Sandbox Code Playgroud) 我有一个包含2个单选按钮的Access 2010表单.一个是和一个没有在选项组.如何获得所选值?
ie - 用户是否选择是或否,使用VBA.
我从一个更大的块中打破了一些代码并需要将工作表传递给它...
我没有为工作表分配任何新值,但我正在更改该工作表的分页符设置.我需要将其作为ByRef传递,还是ByVal足够好?
Private Sub SetPageBreaks(ByRef wsReport As Worksheet)
Dim ZoomNum As Integer
wsReport.Activate
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.ResetAllPageBreaks
ZoomNum = 85
With ActiveSheet
Select Case wsReport.Name
Case "Compare"
Set .VPageBreaks(1).Location = Range("AI1")
ZoomNum = 70
Case "GM"
.VPageBreaks.Add before:=Range("X1")
Case "Drift"
.VPageBreaks.Add before:=Range("T1")
Case Else
.VPageBreaks.Add before:=Range("U1")
End Select
End With
ActiveWindow.View = xlNormalView
ActiveWindow.Zoom = ZoomNum
End Sub
Run Code Online (Sandbox Code Playgroud) 我有一个运行以下代码的宏,用于将数据从一个 Excel 文件复制到另一个 Excel 文件中。目前,它正在将数据复制并粘贴到第二个 Excel 文件中。这意味着它会覆盖第二个 Excel 文件中的所有数据。
我希望它插入复制的单元格,而不是粘贴工作簿中已有的数据。我应该如何编辑第 27 行才能使其正常工作?
我想我需要使用以下代码,但我不确定如何将其应用到我的原始代码中。
InsertCopiedCells
Run Code Online (Sandbox Code Playgroud)
这是粘贴数据的原始代码。
Const strFile As String = "E:\My Documents\file2\file\MonthlyReports\Data\file1.xlsx"
'Add the file location
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet
Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet
'-------------------------------------------------------------
'Open file with data to be copied
Set wbCopyFrom = Workbooks.Open(strFile)
Set wsCopyFrom = wbCopyFrom.Worksheets(1)
'--------------------------------------------------------------
'Copy Range
wsCopyFrom.Range("A2:AA5000").Copy
wsCopyTo.Range("A2").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Run Code Online (Sandbox Code Playgroud) 我使用此代码创建一个新工作表并列出工作簿中的所有工作表名称,它们之间有空行,然后它隐藏工作表名称之间的所有空行.
但它接管一分钟完成是否有更有效的方法来做到这一点?
Sub ListAllSheetNames()
'Disabling the following to speed up the vba code
ActiveSheet.DisplayPageBreaks = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'code to create new sheet and list all sheet names in workbook
Dim xWs As Worksheet
On Error Resume Next
xTitleId = "All Sheet Names"
Application.Sheets(xTitleId).Delete
Application.Sheets.Add.Index
Set xWs = Application.ActiveSheet
xWs.Name = xTitleId
For i = 2 To Application.Sheets.Count
'Edit this to adjust the row spacing, number after *
xWs.Range("A" & ((i - 2) …Run Code Online (Sandbox Code Playgroud)