Tag: 全局variables

循环遍历行并将单元格值存储为variables以运行fomrulas,最终导致另一个单元格

我想扫描每一行,并拉出某些单元格并将它们存储为variables。 当我到达行的末尾时,我想运行一系列的公式和vlookups。 我有公式和vlookups都设置,但我需要扫描每一行,然后把这些公式的结果,并把它们放回另一个单元格。 这里是示例代码 Dim height As Double Dim weight As Double Dim gender As String Dim newWeight as Double 'I'd like to set the loop here 'for each row do this height = d2.value weight = f2.value gender = k2.value 'then run through my equations If gender = "F" and weight < 20 Then […]

使用长整型variables行VBA

我有我想用来总结变长度行的代码的下面的代码片段 Dim LR As Long LR = ActiveSheet.Range("Total").Row With Worksheets("Post Implementation Costs") .Range("AD" & LR).Formula = "=Sum("AD7:AD"& LR – 1)" End With 当LR = 15时,我希望结果=SUM(AD:AD14)但是现在它返回=Sum(AD7: & LR -1)

VBA – 在.formula中variables

有一个更优雅(更简单)的方法来把variables放在.formula中吗? 我不想使用.formulaR1C1 我有这个代码: Range("C8").Select Selection.End(xlDown).Select PosR = ActiveCell.Row KonR = PosR – 2 Range("N" & PosR).Select aAddress = Range("$N$9").Address & ":" & Range("$N$" & KonR).Address ActiveCell.Formula = "=SUM(" & aAddress & ")" 很明显,我想把=SUM($N$9:$N$101) (101是最后一个单元格减2)放到那个单元格中,这段代码完成这个工作。 但我只是想确定这是最简单的方法。

如何使用Recordset使用variables!

我的问题是以下几点: 我需要为logging集分配一个值。 问题是我需要使用一个variables。 所以,而不是写这个 MyRecordSet![field_name] 我需要写这个 MyRecordSet![variable_name] 即使对我来说,这一切看起来都很简单,直到我发现括号内没有引号将variables名称中的文本string分开。 所以,我无法区分它们。 拜托,伙计们,帮帮我! 我试过了你能想象到的一切。 提前致谢。

VBA Excel – variables“双”function

我被赋予了一个VBA函数,但是我不明白它是如何工作的,并且会感激你的帮助,因为按照写它的方式,微积分是非常长的(基本算术* 15 000行) 我的问题来自DoublevariablesQty_Level的定义,定义如下: Dim Qty_Level(30) As Double 我从来没有见过像这样定义的variables,像一个函数一样的括号。 这是我的代码: Sub cumul() Dim i As Long Dim j As Integer Dim Qty_level(30) As Double Dim Col_Niveau As Integer Dim Col_Quantite As Integer Dim Col_Resultat As Integer i = InputBox("Veuillez indiquer le numéro de la première à analyser (numéro de ligne Excel)", "Ligne de départ") Col_Niveau […]

VBA从模块(excel)更改实例variables

在VBA中,我需要一个模块子来告诉一个实例来设置一些variables。 在模块1中我有: Sub Load() ThisWorkbook.SetupVariables ThisWorkbook.TestVariables End Sub 在ThisWorkbook中我有: Private Variable1 As Integer Private Variable2 As String Private Variable3 As MyUserDefinedObjectType Public Sub SetupVariables() Variable1 = 5 Variable2 = "Five" Set Variable3 = New MyUserDefinedObjectType() End Sub Sub TestVariables() MsgBox Variable1 & " is spelled " & Variable2 Variable3.SomeFunction End Sub Load()内的TestVariables调用产生正确的结果,但后续对TestVariables的调用失败。 我怎样才能使Variable1和Variable2保持其值? (在我现实世界的情况下,这些variables是我定义的对象,不能作为公共variables。) 事件顺序: […]

VLOOKUP并填充date范围内的所有单元格

我有两张床单: – 预订从表单( car nr , registration nr , car model , starting date和return date )获取数据。 registration nr和car model是通过查找来自dispo) – dispo实际上只是一天的所有date在第一行和前四列的日历: car nr , registration nr , car model和today的date。 我的程序必须将表单中的数据注册到“预订”(即工作),然后从这个单元中find“dispo”对应的starting date和car nr并在其中放置一个“x”(其实我想要在starting date和return date)之间的所有单元格中都有一个“x” return date) 。 现在, car nr固定为1.这是我的代码: Private Sub cmdajout_Click() Dim dispo As Worksheet Dim booking As Worksheet Dim db As Range […]

Excel VBA在其他工作簿中使用数据透视表数据

以下Sub要求用户select要打开的通用模板,然后要求用户select一个源文件(以填充模板)。 源文件包含许多工作表和数据透视表。 然后子从数据透视表中select数据并将其复制到模板中。 我需要源文件是一个variables与硬编码的数据透视表源bc这个标题根据用户的select而改变。 问题1:当数据被复制时,只显示REF! 而不是实际的数据(即使数据存在)。 'Open Generic Report to populate with data Dim GenericFolderLocation As String MsgBox "Please select the generic porfolio template…" GenericFolderLocation = "C:\Users\user.name\Desktop" ChDrive GenericFolderLocation SelectedFile = Application.GetOpenFilename( _ fileFilter:="Excel Files (*.xls*), *.xls*", MultiSelect:=False) Workbooks.Open (SelectedFile) Set test = ActiveWorkbook Dim SourceFolderLocation As String Dim FileName As String Dim SourceFile As […]

使长variables在64位和32位Excel VBA中工作

我有一个相当复杂的Excel VBA项目,在32位系统上运行良好,现在我正试图使它在64位系统上也能工作。 我已经解决了所有的函数声明,但仍然得到一些与Long数据types的问题。 做一些研究,我想出了这个(从MSDN页面): LongPtrparsing的实际数据types取决于它所运行的Office的版本: LongPtr在32位版本的Office中parsing为Long , LongPtr在64位版本的Office中parsing为LongLong 。 但这是否意味着我可以改变我所有的Dim语句 Dim x as Long 至 Dim x as LongPtr 我应该到处做吗? 或者我得到了棍棒的错误结局? 有没有什么情况可以避免这种变化?

可变大小的公共数组variables

我想在Excel VBA中的全局数组variables的数组大小取决于第二个全局variables。 我正在尝试这样的事情 Public int1 As Integer Sub foo() int1 = '##read from ini file Public varArray(1 To int1) As Variant For i = 1 To int1 varArray(i)= '##read from ini file Next i Call SomeProcedure '##in another module where varArray is used End Sub 现在显然这是行不通的,因为全局公式必须在sub之外进行声明,而且当我给它们一个范围的时候,arrays也需要一个常数。 有没有什么办法可以通过声明来实现呢? Public varArray() As Integer 然后再给它一些元素? 似乎没有让我这样做,没有别的我试过…