VB:test计算列X中有多少连续行 - 单元格具有点“。”。从活跃的细胞下来 [英] VB: test Count how many consecutive rows-cells in column X have a dot "." from the active cell down

查看:30
本文介绍了VB:test计算列X中有多少连续行 - 单元格具有点“。”。从活跃的细胞下来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原谅,原标题不准确(不断变化), 我正在研究这个&在帖子中有更准确的简要说明:181007以下。 我会回复我提出的问题&可能不需要回复,除非您看到1个班轮的修正,例如在
帖子中。 旧标题:

pardon, original title was not accurate (changing),  i am working on this & have more accurate-brief in post: 181007 below.  i will post back what i come up with & may not need a reply just yet unless you see a fix for 1 liner eg in that post.  old title:

VB:需要测试activecell.row的行,列A,左,1).text ="。" (但是A向下延伸x行数)

VB: Need line for test activecell.row, column A, Left, 1).text = "." (but for A to extend down x number of rows)

----------

----------

 我正在寻找可能是1个班轮(或那些约)来测试A列是否是工作行。 他们都有 一个左字符,1)="。"

  i am looking for what may be a 1 liner (or there abouts) to test if column A is a work row.  they all have  a left character, 1) = "."

我可以为一行执行此操作,但花了一些时间尝试从当前行向下延伸5行。  例如:

i can do that for one line, but spent some time trying to get to work for extending down 5 rows from the current row.  eg have:

    '如果是左(细胞(activecell.row,"A:A")。文本,1)="。"。然后    '是

    'If Left(Cells(activecell.row, "A:A").Text, 1) = "." Then    'yes

请原谅,我可以做一些中等大小的事情,但要点击很多小的语法项目。 我可以列出我在下面尝试的一些变化(更多是为了嘲笑我猜)。 如果大致:

pardon, i can do some medium size things, but take hits on a lot of small syntax items.  i can list some of the variations i tried below (more to laugh at i guess).  if roughly:

    '如果是左(细胞(RANGE(activecell.row).RESIZE(5,0),"A:A")。Text,1)="。"然后    '剩下的所有5行1 ="。"从选定行向下列:A

    'If Left(Cells(RANGE(activecell.row).RESIZE(5,0), "A:A").Text, 1) = "." Then    'ALL 5 rows left 1 = "." from selected row down for column: A

提前感谢。 如果接下来的5行是工作行,则目的是退出指定点的点击事件。

thanks in advance.  the purpose will be for exit a click event at a spec point, if the next 5 rows are work rows.

 

 

==========   注:  (只是左边的过滤,尝试过多的变化;需要使用activecell.row而不是activewindow; 点击事件的一部分)

==========    NOTES:  (just the left overs,  trying too many variations;  need to use activecell.row instead of activewindow;  part of a click event)

 

 

  

  

如果1然后



   如果RANGE("a1:a2"),则值="。"然后

    '如果是左(单元格(RANGE(activecell.row).RESIZE(5,0),"A:A")。Text,1)="。"然后  'no

    '如果是左(单元格(RANGE(activecell.row).RESIZE(5,0),"A:A")。Text,1)="。"然后  'no

    '如果是左(细胞(activecell.row,"A:A")。文本,1)="。"。然后    '是

      

      MsgBox"是" &安培;空间(10),vbQuestion  '," title" &安培; vbCr&

Else:MsgBox"NO" &安培;空格(10),vbQuestion:结束如果','标题"  &安培; vbCr& ;:结束如果



$
否则

    'RANGE("& ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1&":"&" A"& ActiveWindow.Panes(ActiveWindow.Panes.Count) .VisibleRange.row + 5)'。选择  '是

    'MsgBox'A" &安培; ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row&空格(10),vbQuestion    "YES 结果例如:  A2145

    'RANGE(" A& ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row).Select    "和;空格(10),vbQuestion    "YES 左上方窗格,左上方单元格选择





'ANS: 到目前为止¥b $ b    Dim rngXX As RANGE:设置rngXX = RANGE("A"和"ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1&":"&"A"& ActiveWindow.Panes (ActiveWindow.Panes.Count).VisibleRange.row +
5)  "。选择  '是

    "昏暗rngXX作为RANGE:设置rngXX = RANGE(QUOT; A"&安培; ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1):rngXX.Select"FRIGGIN YES&安培; ":" &安培; " A" &安培; ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row
+ 5)  "。选择  '是

    "rngXX.Select  "YES 如果某个范围内的所有单元格=一个值,则获取该数据为b
$ b    'MsgBox Left(rngXX.Value,1)&空格(10),vbQuestion   "YES 答案(单细胞)

    'MsgBox rngXX.Value&空间(10),vbQuestion  '是

    

   如果是左(RANGE("a2132")。RESIZE(5,0).Value,1)="。"。然后  'no

    '如果是左(RANGE("a2132")。值,1)="。"。然后   '是

    '如果是左(RANGE("a2132:a2135")。值,1)="。"。然后    'no

    

    '如果左(rngXX.Value,1)="。"然后    '是单细胞为是
      MsgBox"是" &安培;空间(10),vbQuestion  '," title" &安培; vbCr&

Else:MsgBox"NO" &安培;空格(10),vbQuestion:结束如果','标题"  &安培; vbCr&:结束如果



    'Cells(rnxx.row,D2).RESIZE(,3)。选择

    '细胞(activecell.row,D2).RESIZE(,3)。选择    "YES 包容性,积极的吗? (连续3个单元格选择:CY99:CZ99)





    '是:

    'Dim rngYY As RANGE:设置rngYY = RANGE("A"& ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 5):rngYY.Select   '是

    

    'Dim rngYY As RANGE:设置rngYY = RANGE("A"& ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row)    'no

    "昏暗rngZZ作为RANGE:设置rngZZ = RANGE(rngYY.OFFSET(1,0)&安培;":"&安培; rngYY.OFFSET(6,0))

  &NBSP ; 'RANGE(rngZZ&":"& rngZZ.OFFSET(5,1))。选择    "不, 不用逗号, 什么 范围行单元格

    '细胞(RANGE(rngZZ&":"& rngZZ.OFFSET(5,1)))。选择    "不, 不用逗号, 什么 范围行单元格

    

    

    '不相交(目标,范围(范围(G7),范围(G7).OFFSET(-10,0)))什么都没有   '例如

    "rngZZ.Select  '不是
    'rngYY.OFFSET(1,0)。选择   '是

    'RANGE(rngYY&":"& rngYY + 1)。选择    'no

    "rngYY.Select&NBSP;&NBSP; "<是的是
    

'    RANGE(rngYY,1).OFFSET(5,0)。选择    "否NBSP;&NBSP;&NBSP; (ROW,COL)

    '细胞(rngYY,1).RESIZE(5,1)。选择    "否NBSP;&NBSP;&NBSP; (ROW,COL)

    '单元格(rngYY,1).OFFSET(,1).RESIZE(,6)。选择    '?$
    'Cells(ActiveCell.row,J6).OFFSET(,1).RESIZE(,6).Select   '例如cols?

    

    'Dim rngZZ As RANGE:设置rngZZ = RANGE(细胞(rngYY.row + 1,1)&":& Cells(rngYY.row + 5,1))'no  ck范围的东西

    'rngZZ。选择

    

'   暗淡rngXX作为RANGE:昏暗rngYY作为RANGE:设置rngXX =细胞(QUOT; A"&安培; ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row)

"&NBSP;&NBSP;&NBSP ;设置rngYY = RANGE(rngXX&":"& rngXX + 5)   '不是?

'    rngYY.Select&NBSP;&NBSP; '不?

If 1 Then

    If RANGE("a1:a2").Value = "." Then
    'If Left(Cells(RANGE(activecell.row).RESIZE(5, 0), "A:A").Text, 1) = "." Then  'no
    'If Left(Cells(RANGE(activecell.row).RESIZE(5, 0), "A:A").Text, 1) = "." Then  'no
    'If Left(Cells(activecell.row, "A:A").Text, 1) = "." Then    'yes
      
      MsgBox "YES" & Space(10), vbQuestion  ', "title" & vbCr &
Else: MsgBox "NO" & Space(10), vbQuestion: End If ', "title"  & vbCr &: end if


Else
    'RANGE ("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1 & ":" & "A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 5)'.Select  'YES
    'MsgBox "A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row & Space(10), vbQuestion    'YES  result eg:  A2145
    'RANGE("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row).Select    '& Space(10), vbQuestion    'YES  top left pane, top left cell selected


'ANS:  so far
    Dim rngXX As RANGE: Set rngXX = RANGE("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1 & ":" & "A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 5)  '.Select  'YES
    'Dim rngXX As RANGE: Set rngXX = RANGE("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 1): rngXX.Select 'FRIGGIN YES & ":" & "A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 5)  '.Select  'YES
    'rngXX.Select  'YES  get if all cells in a range = a value

    'MsgBox Left(rngXX.Value, 1) & Space(10), vbQuestion   'YES  ANSWER (for single cell)
    'MsgBox rngXX.Value & Space(10), vbQuestion  'YES
    
    If Left(RANGE("a2132").RESIZE(5, 0).Value, 1) = "." Then  'no
    'If Left(RANGE("a2132").Value, 1) = "." Then   'yes
    'If Left(RANGE("a2132:a2135").Value, 1) = "." Then    'no
    
    'If Left(rngXX.Value, 1) = "." Then    'yes for single cell
      MsgBox "YES" & Space(10), vbQuestion  ', "title" & vbCr &
Else: MsgBox "NO" & Space(10), vbQuestion: End If ', "title"  & vbCr &: end if

    'Cells(rnxx.row, D2).RESIZE(, 3).Select
    'Cells(activecell.row, D2).RESIZE(, 3).Select    'YES  inclusive, positive only? (3 cells in a row selected: CY99:CZ99)



    'YES:
    'Dim rngYY As RANGE: Set rngYY = RANGE("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row + 5): rngYY.Select   'YES
    
    'Dim rngYY As RANGE: Set rngYY = RANGE("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row)    'no
    'Dim rngZZ As RANGE: Set rngZZ = RANGE(rngYY.OFFSET(1, 0) & ":" & rngYY.OFFSET(6, 0))
    'RANGE(rngZZ & ":" & rngZZ.OFFSET(5, 1)).Select    'no,  no on commas,  WHAT  range rows cells
    'Cells(RANGE(rngZZ & ":" & rngZZ.OFFSET(5, 1))).Select    'no,  no on commas,  WHAT  range rows cells
    
    
    'Not Intersect(Target, RANGE(RANGE(G7), RANGE(G7).OFFSET(-10, 0))) Is Nothing   'eg
    'rngZZ.Select  'NO
    'rngYY.OFFSET(1, 0).Select   'yes
    'RANGE(rngYY & ":" & rngYY + 1).Select    'no
    'rngYY.Select   '< yes
    
'    RANGE(rngYY, 1).OFFSET(5, 0).Select    'no    (ROW, COL)
    'Cells(rngYY, 1).RESIZE(5, 1).Select    'no    (ROW, COL)
    'Cells(rngYY, 1).OFFSET(, 1).RESIZE(, 6).Select    '?
    'Cells(ActiveCell.row, J6).OFFSET(, 1).RESIZE(, 6).Select   'eg cols?
    
    'Dim rngZZ As RANGE: Set rngZZ = RANGE(Cells(rngYY.row + 1, 1) & ":" & Cells(rngYY.row + 5, 1)) 'no  ck range stuff
    'rngZZ.Select
    
'    Dim rngXX As RANGE: Dim rngYY As RANGE: Set rngXX = Cells("A" & ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.row)
'    Set rngYY = RANGE(rngXX & ":" & rngXX + 5)   'no?
'    rngYY.Select   'no?

推荐答案

I我不确定以下是否是您要做的事情,但如果没有,那么我将需要您的数据的示例副本以及您要实现的目标的描述。

I am not sure if the following is what you are trying to do but if not then I will need an example copy of your data with a description of what you are trying to achieve.

代码循环遍历A列中的所有单元格并测试它们的点,然后应用"是"。或"否"使用Offset命令到右边的列。

The code loops through all cells in column A and tests them for the dot and then applies the "Yes" or "No" to a column to the right with the Offset command.

注意,在我使用offset的地方,0(零)用于行(行没有偏移),3用于列。列数基于 如果您将光标放在A列中,然后是您需要按右箭头
到达所需列的次数(在示例中它是D列)如果它插入"是"或"否",请编辑3以匹配您需要"是"或"否"的列。

Note that where I use offset, the 0 (zero) is for rows (there is no offset for rows) and the 3 for columns. The number of columns is based on if you place the cursor in column A and then it is the number of times you need to press the right arrow to get to the required column (In the example it is column D where it inserts "Yes" or "No" so edit the 3 to match the column where you require the "Yes" or "No".

确保你在运行代码之前备份工作簿,因为我不确定你想要做什么你想做什么。

子测试()

    Dim rngColA As Range

    Dim rCel As Range

   

   使用ActiveSheet

       '以下行分配单元格A2到列A中最后一个使用的单元格到范围变量

       设置rngColA = .Range(.Cells(2," A" ),。细胞(.Rows.Count,"A")。E nd(xlUp))

   结束与$
   

    '遍历A栏中的所有单元格。
   对于每个rCel In rngColA

       如果左(rCel,1)="。"然后是
            '跟随线插入'是'是A列右侧的3个单元格(在D栏中)

            rCel.Offset(0,3)=" Yes"

       否则为
            '跟随线插入'是'是A列右侧的3个单元格(在D栏中)

            rCel.Offset(0,3)=" No"

       结束如果是
   下一个rCel

    Dim rngColA As Range
    Dim rCel As Range
   
    With ActiveSheet
        'Following line assigns cell A2 to the last used cell in column A to the range variable
        Set rngColA = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
    End With
   
    'Loop through all the cells in column A
    For Each rCel In rngColA
        If Left(rCel, 1) = "." Then
            'Following line inserts "Yes" 3 cells to right of column A (In column D)
            rCel.Offset(0, 3) = "Yes"
        Else
            'Following line inserts "Yes" 3 cells to right of column A (In column D)
            rCel.Offset(0, 3) = "No"
        End If
    Next rCel

结束子

如果代码不起作用,则将示例工作簿上传到OneDrive描述你想要实现的目标。

If the code does not work then upload an example workbook to OneDrive with a description of what you want to achieve.

在OneDrive上传工作簿的指南。 (如果您已经使用OneDrive并且保存到它的过程不同,那么您可以从步骤8开始获取链接,但请在上传之前压缩文件。)

Guidelines to upload a workbook on OneDrive. (If you already use OneDrive and your process for saving to it is different then you can probably start at step 8 to get the link but please zip the file before uploading.)


  1. 压缩工作簿。不要只是将解压缩的工作簿保存到OneDrive,因为工作簿使用On-Line Excel打开,并且使用On-Line版本的有限功能会导致问题。
  2. 要压缩文件:在Windows资源管理器中右键单击所选文件,然后选择发送至 - >压缩(zipped)文件夹)。通过按住Ctrl键并在每个文件上单击鼠标左键,您可以选择多个工作簿,然后右键单击其中一个选项
    以发送到压缩文件,它们将全部包含在一个Zip文件中。
  3. 不要使用第三方压缩应用程序,因为我无法解压缩它们。当Windows提供完美的应用程序时,我不会使用第三方应用程序阻塞我的计算机。
  4. 转到此链接。  https://onedrive.live.com
  5. 使用您在此论坛中使用的相同登录ID和密码。
  6. 在顶部的蓝色栏中选择上传,然后浏览到要上传的压缩文件夹。
  7. 选择打开(或双击)。 (请耐心等待,并在最初看到弹出窗口表示已完成后给它时间显示文件。)
  8. 右键单击OneDrive上的文件,然后选择共享。
  9. 选择"获取"一个链接"从弹出菜单中。
  10. 单击显示链接的字段,然后突出显示,然后将链接复制并粘贴到此论坛的回复中。 (我建议您避开"获取链接"屏幕上的"复制"按钮,因为它会引入不需要的额外步骤
    。)
  1. Zip your workbooks. Do not just save an unzipped workbook to OneDrive because the workbooks open with On-Line Excel and the limited functionality with the On-Line version causes problems.
  2. To Zip a file: In Windows Explorer Right click on the selected file and select Send to -> Compressed (zipped) folder). By holding the Ctrl key and left click once on each file, you can select multiple workbooks before right clicking over one of the selections to send to a compressed file and they will all be included into the one Zip file.
  3. Do not use 3rd party compression applications because I cannot unzip them. I do not clog up my computer with 3rd party apps when there are perfectly good apps supplied with windows.
  4. Go to this link.  https://onedrive.live.com
  5. Use the same login Id and Password that you use for this forum.
  6. Select Upload in the blue bar across the top and browse to the zipped folder to be uploaded.
  7. Select Open (or just double click). (Be patient and give it time to display the file after initially seeing the popup indicating it is done.)
  8. Right click the file on OneDrive and select Share.
  9. Select "Get a Link" from the popup menu.
  10. Click in the field displaying the link and it should highlight and then Copy and Paste the link into your reply on this forum. (I suggest that you avoid the "Copy" button on the "Get a link" screen because it introduces additional steps that are not required.)


这篇关于VB:test计算列X中有多少连续行 - 单元格具有点“。”。从活跃的细胞下来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆