[英]VBA Macro - Receiving Offset Object Defined Error
I'm trying to loop through the rows in a column of a spreadsheet in which there is a time in column 1, a date in column 2, and a value in column 3. the value changes every now and then and I need to single the times out that the value was changed. 我正在尝试遍历电子表格的一列中的行,其中在第1列中有一个时间,在第2列中有一个日期,在第3列中有一个值。该值不时更改,我需要单超时,该值已更改。 I have the following code which gives me a (run time error 1004- application defined or object defined error) and highlites
我有以下代码,给我一个(运行时错误1004-应用程序定义或对象定义的错误)和高级提示
activecell.offset(-1,0).Range("A1").select
I have been trying to fix it/research the problem most of the afternoon but can't get an answer that works for me. 我一直在试图解决它/研究整个下午的问题,但找不到适合我的答案。 any help would be appreciated
任何帮助,将不胜感激
Sub Timestamp
Range("C1").Select
While ActiveCell.Value <> ""
Number = ActiveCell.Value
Counter = Counter +1
activecell.offset(-1,0).Range("A1").select
If ActiveCell.Value <> Number Then
activecell.offset(-1,0).Range("A1").select
Time = ActiveCell.Value
Sample = Sample +1
activecell.offset((Counter - Sample),3).Range("A1").select
ActiveCell.Value = Time
activecell.offset(-(Counter - Sample),-1).Range("A1").select
End If
Loop
End Sub
You don't need to select the cells to get their values. 您无需选择单元格即可获取其值。 All you need is to refer to them.
您只需要参考它们即可。 VBA is an Object Oriented programming language.
VBA是一种面向对象的编程语言。 Take a look at this document for basics: Object Oriented VBA
看一下本文档的基础知识: 面向对象的VBA
As far as getting a count of the times the Number changes, this should give you that value and you can add in any additional code you need to be handling. 至于获得Number更改次数的计数,这应该为您提供该值,并且您可以添加需要处理的任何其他代码。
Option Explicit
Sub test()
Dim rng As Range
Dim number As Long
Dim counter As Integer
Set rng = Range("C1")
Do While rng.Value <> ""
number = rng.Value
If rng.Offset(1, 0).Value <> number Then
counter = counter + 1
End If
Set rng = rng.Offset(1, 0)
Loop
MsgBox counter & " changes"
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.