[英]How to get text from cell to another in Excel
Ok, 好,
So I am trying to count a bunch of cells containing certain data which works fine. 因此,我试图计算一堆包含某些正常工作数据的单元格。 I am now trying to add date to that criteria which is typed into another cell.
我现在正在尝试将日期添加到该标准中,然后将该标准键入另一个单元格中。 The issue with his is that the cells contain Date and Time and I only want to filter cells which "contain" a specific date.
他的问题是单元格包含“日期和时间”,我只想过滤“包含”特定日期的单元格。
This is my formula =COUNTIFS(Sheet3!G:G,"example",Sheet3!AC:AC,C50,Sheet3!AB:AB,A$48) Column AB being the date/time. 这是我的公式= COUNTIFS(Sheet3!G:G,“ example”,Sheet3!AC:AC,C50,Sheet3!AB:AB,A $ 48)AB列是日期/时间。 I want to be able to right a date into A48 and then have a count of all cells that contain that date, but it wont work as there is also Time in the cell.
我希望能够将日期改成A48,然后对包含该日期的所有单元格进行计数,但是由于该单元格中还有时间,因此无法正常工作。 Is there anyway of excluding the date?
反正有排除日期吗?
I have also tried running a bit of code. 我也尝试过运行一些代码。 This fixes my time issue, but the code doesn't stop when it encounters a blank cell.
这解决了我的时间问题,但是遇到空白单元格时代码不会停止。 How could I make it do this?
我怎样才能做到这一点? Or if I can solve the above I wont need the code at all.
或者,如果我可以解决上述问题,那么我根本不需要代码。 This is the code.
这是代码。
Sub ConvertDates()
'Updateby20140529
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = VBA.Int(Rng.Value)
If IsEmpty(WorkRng) Then Exit Sub
Next
WorkRng.NumberFormat = "mm/dd/yyyy"
End Sub
Thanks a bunch. 谢谢你
Please try: 请试试:
=COUNTIFS(Sheet3!G:G,"example",Sheet3!AC:AC,C50,Sheet3!AB:AB,">="&A$48,Sheet3!AB:AB,"<"&A$48+1)
This should count based on any value in AB being greater than or equal to the date (without time) in A48 and less than one day later than that day - hence spanning whatever the times are. 这应基于AB中大于或等于A48中日期(无时间)且比该日期晚一天以下的任何值进行计算-因此可以跨越任何时间。
Where I am at present this is equivalent to 27/11/2015
in A48 and: 我目前所处的位置相当于A48中的
27/11/2015
,并且:
">="42335,Sheet3!AB:AB,"<"42335+1
for the last part of the above formula - since time in Excel datetime serial is the decimal part of a day index. 对于上述公式的最后一部分-由于Excel datetime序列中的时间是日索引的小数部分。
It seems to me that the OP has two questions: 在我看来,OP有两个问题:
This fixes my time issue, but the code doesn't stop when it encounters a blank cell.
这解决了我的时间问题,但是遇到空白单元格时代码不会停止。
1) How could I make it do this?
1)我怎样才能做到这一点?
2) Or if I can solve the above I wont need the code at all.
2)或者,如果我可以解决上述问题,我根本不需要代码。
With the second question already answered by @pnuts by the formula: 第二个问题已经由@pnuts通过以下公式回答:
=COUNTIFS(Sheet3!G:G,"example",Sheet3!AC:AC,C50,Sheet3!AB:AB,">="&A$48,Sheet3!AB:AB,"<"&A$48+1)
Let's look at the first question. 让我们看第一个问题。
The macros does not stop for two reasons: 宏不会停止的原因有两个:
Instead of validating the cell value using IsEmpty(Rng.Value2)
, it validates the entire range provided by the user using IsEmpty(WorkRng)
代替使用验证单元值的
IsEmpty(Rng.Value2)
它验证通过使用用户提供的整个范围内IsEmpty(WorkRng)
The validation occurred after the value of the cell is restated with Rng.Value = VBA.Int(Rng.Value)
so the cell will never be empty at the time of validation. 验证发生在用
Rng.Value = VBA.Int(Rng.Value)
重述单元格的值之后,因此验证时该单元格永远不会为空。
This is your revised code, I have done also other small modifications. 这是您修改的代码,我也做了其他小的修改。
Sub ConvertDates_Original()
Const kTitleId = "Kutools for Excel"
Dim Rng As Range, WorkRng As Range
On Error Resume Next
Set WorkRng = Application.InputBox("Range", kTitleId, Selection.Address, Type:=8)
If WorkRng Is Nothing Then Exit Sub
For Each Rng In WorkRng
With Rng
If IsEmpty(.Value2) Then Exit Sub
.Value = Int(.Value2)
.NumberFormat = "mm/dd/yyyy"
End With: Next
End Sub
Suggest to visit these pages to obtain a deeper understanding of the changes done: 建议访问以下页面,以更深入地了解所做的更改:
Range Object (Excel) , Variables & Constants 范围对象(Excel) , 变量和常量
Let me know of any question you might have about the code and changes done. 让我知道您可能对代码和所做的更改有任何疑问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.