如何编辑logging的macros程序,以便它可以识别每当我更改导入的input文件时一直持续到最后一个值?

我已经logging了一个有7张工作簿的macros。 两张纸从多个文本文件中导入数据并按顺序排列。 其他表格使用这些数据和一些其他公式,并用多项式方程式生成图表。 所以macros观scheme是相当大的。 我有这样的数据

ABCDE R8 0 # * @ $ R9 0.05 # * @ $ R10 0.1 # * @ $ . . . . . . . . . . . . . . . . . . R108 5.0 # * @ $ 

在以上数据中:
从第8行到第108行的列A和B是导入的数据
C,D&E由公式给出。

我的问题是我没有在我导入的列A(0〜5)相同的数据。

数据不断变化,如0〜12,0〜16和0〜40。 所以最后的行号也是每次都改变。 因此,每次数据更改时,我都需要为所有其他数据loggingmacros。

我可以编辑我logging的macros,它不会停止在第108行(或5.0),但停止在最后一个给定的input值(比如'R88'或40.0或'R168'或16.0等等。)?

第8行给出的C,D&E中给出的公式应该延长到最后一行作为input。

例如,假设我在sheet2的A和B列中input的值为0〜40或0〜16的文本文件。 现在我希望这些值在表1的A和B列的第8行以及C,D和E列中给出的相应公式应该延伸到第88行或第168行。表1中的值必须随着变化发生导入的文本文件无论行数还是递增步长值。

  ABCDEABCDE R8 0 # * @ $ R8 0 # * @ $ R9 0.2 # * @ $ R9 0.25 # * @ $ R10 0.4 # * @ $ R10 0.5 # * @ $ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . R88 16.0 # * @ $ R168 40.0 # * @ $ 

请帮我解决这个问题..

如果您的数据在每个工作表的同一个单元格中启动 ,则可以使用一些基本的Excelselect命令来获取所有数据。

 'Set up a range object. Dim rng As Range 'Select the first cell in which data is going to be. This example uses cell "A1". Range("A1").Select 'The following line is equivalent to pressing Shift-End-DownArrow, which selects 'everything in the current column until an empty cell is encountered. Range(Selection, Selection.End(xlDown)).Select 'The following line is equivalent to pressing Shift-End-RightArrow, which selects 'everything in the current row until an empty cell is encountered. Range(Selection, Selection.End(xlToRight)).Select 'This selection is then a range containing all the continuous entries starting at cell A1. 'Set the Range variable to the current selection. Set rng = Selection 

将值分配给对象variables时,在VBA中使用Set关键字很重要。

将这些数据粘贴到目标后,可以使用类似的方法来获取它所占用的范围,并使用以下函数确定应该在哪里复制公式。

Range.Column返回范围中的第一个列号。
Range.Columns.Count返回指定范围内的列数。
Range.Row返回范围中的第一行。
Range.Rows.Count返回范围内的行数。
在所有上述function中,您将用您的实际范围对象replaceRange

如果从文本文件编译数据的代码是有效的,也就是说,工作表从单元格A1开始,不跳过行或列,并且在期望的数据范围外没有杂散的非空白单元格,最简单的方法是:

 Set rng = ActiveSheet.UsedRange 

或者

 Set rng = ActiveSheet.Range("A1").CurrentRegion 

要指定从单元格C8到结尾的范围,请填写公式:

 With ActiveSheet.UsedRange Set rng = .Offset(7, 2).Resize(.Rows.Count - 7, 3) End With 

如果公式已经存在于单元格C8:E8中,那么这个

 With ActiveSheet.UsedRange .Offset(7, 2).Resize(.Rows.Count - 7, 3).FillDown End With