- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为可变长度数据集中的每个样本创建一个唯一的 ID。为此,我想使用名为 Name 和 Sample Type 的两个数据字符串的一部分。我希望我沿着列中的每一行向下走并取出每个字符串的片段并将它们放在一起,但是当我单步执行循环时,它永远不会进入我的循环,只会在它周围。有人能告诉我为什么吗?
Sheets("Data").Activate
setlastrow = Sheets("Data").Range("b5000").End(xlUp).Row
setlastcol = Sheets("Data").Cells(5, Columns.Count).End(xlToLeft).Column 'this is still assuming that row 5 has the header in it
colname = Rows(5).Find("Name", LookAt:=xlWhole).Column ' this can be repeated for any other columns we want to asign values to. These variables will make the rest of this much easier
colSampleText = Rows(5).Find("Sample Text", LookAt:=xlWhole).Column
For i = 6 To lastrow
Sheets("Data").Range(Cells(i, 1)) = workbookfunction.if(workbookfunction.CountIf(Range(Cells(6, colname), Cells(i, colname)), Cells(i, colname)) < 10, "0", "") & workbookfunction.CountIf(Range(Cells(6, colname), Cells(i, colname)), Cells(i, colname) & "-" & Left(Cells(i, colSampleText), 5))
'this should find the unique identifying infomation for each sample and analyte
Next i
最佳答案
您的代码中有两个主要错误 - 加上一个小错误。一是结构性的。您声明非您使用的变量。这就像在说,“既然我不会开车,我还不如闭上眼睛,我们加速前进”。这并非没有逻辑,但对于将您带到您想去的地方几乎没有什么帮助。
另一个是您希望 VBA 执行的工作表函数和您希望分配给 Excel 执行的单元格的函数之间的混淆。将复杂的公式写入单元格比让 VBA 计算复杂的公式更困难。对于该方法,如果要在 VBA 中创建公式,应首先将其分配给字符串,例如 MyFormula = "=COUNTIF(D6:D12, "MyName")"
然后,在测试之后,将该字符串分配给单元格的 Formula
属性,例如 Cells(R, ClmName).Formula = MyFormula"
.在下面的代码中,我选择让 VBA 进行计算。由于并不完全清楚你想要什么(错误的代码永远不是展示你意图的好方法!)请修改它。在 VBA 中比在工作表函数中更容易。
Private Sub Test()
Dim LastRow As Long
Dim LastClm As Long
Dim ClmName As Long ' R use "col" for color, "clm" for column
Dim ClmSampleText As Long
Dim CountRng As Range
Dim Output As Variant
Dim R As Long ' R use R for row, C for column
Sheets("Data").Activate
LastRow = Sheets("Data").Range("b5000").End(xlUp).Row
' this is still assuming that row 5 has the header in it
LastClm = Sheets("Data").Cells(5, Columns.Count).End(xlToLeft).Column
' this can be repeated for any other columns we want to asign values to.
' These variables will make the rest of this much easier
ClmName = Rows(5).Find("Name", LookAt:=xlWhole).Column
ClmSampleText = Rows(5).Find("Sample Text", LookAt:=xlWhole).Column
For R = 6 To LastRow
'this should find the unique identifying infomation for each sample and analyte
Set CountRng = Range(Cells(6, ClmName), Cells(R, ClmName))
Output = WorksheetFunction.CountIf(CountRng, Cells(R, ClmName).Value)
If Output < 10 Then Output = 0
Cells(R, 1).Value = CStr(Output) & "-" & Left(Cells(R, ClmSampleText).Value, 5)
Next R
End Sub
Cell
缺乏了解。目的。一个单元格是
Range
.它有许多属性,例如
Cell.Row
和
Cell.Column
或
Cell.Address
,以及其他属性,如
Cell.Value
或
Cell.Formula
. Value 属性是默认值。因此
Cell
与
Cell.Value
相同
但是 不总是。在这个例子中,通过不考虑
Cell.Value
你也忽略了
Cell.Formula
,并通过放置
Cell
变成
WorksheetFunction
您将 VBA 混淆为您的意思,单元格值或单元格范围。由于所有参与者都感到困惑,结果是可以预见的。
Cell.Value
当您指的是单元格的值并使用
Cell
仅当您指的是范围时。
关于excel - VBA 正在绕过我的 for 循环而不执行它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61378423/
我正在编写国际象棋人工智能程序,并且在实现棋子方格表时遇到了问题。由于我只想每边有一张正方形 table ,因此我需要一个函数来翻转保存 x 轴值的一维数组。例如,这个数组: [ 2, 4, 5, 3
在应用程序中,在尝试使用触摸旋转对象时,我注意到一段时间后对象的位置发生了漂移(没有应用任何平移!!)。旋转仅围绕 z 轴,工作正常,但仅在旋转几次后才会发生漂移。 ds 将用于进行翻译(使用上下按钮
我正在尝试构建金字塔并为其设置动画。问题是在围绕 X 轴旋转它之后,我尝试围绕金字塔的高度(Y 轴)旋转它,但我每次都在移动。我基本上尝试了每个 transform-origin 选项,但它不起作用。
我需要绕其 x 轴(或 y 轴)旋转图像。我可以使用 avisynth 轻松创建这样的动画,但现在我需要使用 Python 的 moviepy 模块来实现该效果。我可以使用以下脚本轻松旋转图像,但需要
我有一个图像被分成两个相等的部分。我正在尝试在悬停时围绕 y 轴将图像的右侧部分旋转 -180°(逆时针)。 问题是有时(随机)图像旋转 180°(顺时针)而不是 -180°(逆时针)。这背后的原因可
如何使用CGAffineTransform(或其他)绕其Y轴旋转UIView?例如,我尝试过: self.image.transform = CGAffineTransform(rotationAng
我正在尝试围绕 y 轴旋转查看器。我有一个名为 tranform_eye() 的函数,它将计算 eyex、eyey 和 eyez 的下一个位置更新。 谁能帮我弄清楚如何计算 eyex、eyey 和 e
我无法解决我遇到的一个奇怪的错误,想知道是否有其他人遇到过类似的问题或可以提供解决方案。 我正在使用 javascript 访问 iOS 设备上的陀螺仪,并且对围绕 z 轴的旋转很感兴趣;我想要设备平
Qt 使用 3x3 变换矩阵进行透视变换和仿射变换。如果矩阵的最后一行等于 [0 0 1],则矩阵被认为是仿射的。由于这个原因,x 轴和 y 轴旋转矩阵是“非仿射”和透视失真结果。但还有进一步的影响。
我是一名优秀的程序员,十分优秀!