简体   繁体   English

宏Excel:将文本插入圆形内的完美方形单元格

[英]Macro Excel: To insert a text into a perfect square cell within a circle shape

How do I insert text into each cell (only perfect square cell) automatically or if there's any other ways? 如何自动插入文本到每个单元格(只有完美的方格单元格)或者是否有其他方法? The label text are 1A, 1B, 1C, 1D, 2A, 2B, 2C, 2D and so on until the end of perfect square cell within the circle. 标签文本是1A,1B,1C,1D,2A,2B,2C,2D等,直到圆内的完美方形单元的末端。 The problem is, the cell has different width and height for each wafer die. 问题是,每个晶片管芯的单元具有不同的宽度和高度。 The range for the row and column within the circle would be different too. 圆圈内行和列的范围也不同。 My question is how do I label the circle automatically or other ways that's possible with the different height and width of the cells. 我的问题是如何自动标记圆圈或使用不同高度和宽度的单元格的其他方式。

Here I attach what my wafer die would look like: 在这里,我附上我的晶圆模具的样子:

晶片管芯的示例

Well, let's suppose that our middle of a circle is located in cell E5 (in left top corner, as shown in your picture). 好吧,我们假设我们的圆圈位于单元格E5 (左上角,如图所示)。 If we want determine if certain cell is within the circle we have to do the following. 如果我们想要确定某个单元格是否在圆圈内,我们必须执行以下操作。 For example, let's check if cell C3 will be included. 例如,让我们检查是否包含单元格C3。 Let's assume that the radius of circle is r . 我们假设圆的半径是r So, now we need to calculate the distance between top left corner of E5 end bottom right of C3. 所以,现在我们需要计算C3底部右下角E5左上角之间的距离。 So you need to calculate the height between the top of E5 and bottom of C3, in this case it will be height of 4th row (more generally, it will be the sume of heights of all rows between), let's call it a . 所以你需要计算E5顶部和C3底部之间的高度,在这种情况下它将是第4行的高度(更一般地,它将是所有行之间的高度的高度),让我们称之为a Then, in similair manner, you calculate distance between left side of E column and right side of C column, so it will the width of D column (more generally, it will be the sum of widths of columns between), let's call it b . 然后,以类似的方式,你计算E列的左侧和C列的右侧之间的距离,因此它将是D列的宽度(更一般地,它将是列之间的宽度之和),让我们称之为b Then you use pitgeorean theorem to calculatte distance between corners: sqrt(a^2 + b^2). 然后你使用pitgeorean定理来计算角之间的距离:sqrt(a ^ 2 + b ^ 2)。 If it's less than r then cell is within the circle. 如果它小于r则单元格在圆圈内。 If you want to determine if the whole cell is within the circle, you must additionally calculate the distance to top right corner of C3. 如果要确定整个单元格是否在圆圈内,则必须另外计算到C3右上角的距离。

I think it gave a grasp on a problem and you are able to generalise it :) 我认为它抓住了一个问题,你可以概括它:)

First of all this is a mathematical problem, before you can perform any labeling action (this will be the very last step), you need to calculate which cells are within the circle. 首先,这是一个数学问题,在您执行任何标注操作之前(这将是最后一步),您需要计算圆圈内的哪些单元格。

Therefore you need to check each cell (loop through) if it is within the circle. 因此,您需要检查每个单元格(循环)是否在圆圈内。
A cell is within the circle if … 如果... 一个单元格在圆圈内

  • The distance between any of the 4 vertexes (corners) of that cell and the center of the circle is less than the radius of the circle: 该单元格的4个顶点(角点)中的任何一个与圆心相距的距离小于圆的半径:
    (x - center_x) 2 + (y - center_y) 2 < radius 2 (x - center_x) 2 +(y - center_y) 2 <radius 2
    where x and y are the coordinates of one vertex and center_x and center_y are the coordinates of the circle center. 其中xy是一个顶点的坐标, center_xcenter_y是圆心的坐标。 This has to be checked for all 4 vertexes of the cell. 必须检查该单元的所有4个顶点。

  • You have to think about if the vertexes have to be … 你必须考虑顶点是否必须......

    • within the circle (formula above) 在圈内(上面的公式)
    • or if a vertex laying exactly on the circle is still ok. 或者如果精确放置在圆上的顶点仍然可以。
      (x - center_x) 2 + (y - center_y) 2 <= radius 2 (x - center_x) 2 +(y - center_y) 2 <=半径2

Now that you have checked all the cells and found out which are within the circle you can start labeling them by looping through the found cells. 现在您已经检查了所有单元格并找出了圆圈内的哪些单元格,您可以通过循环查找找到的单元格来开始标记它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM