excel - 如果范围包含大于 0 的值
问题描述
这个想法是计算一个范围内的单元格数量,并检查每个单元格的值是否大于 0,如果是,则键入“过期”,否则键入“非过期”有人可以帮我吗?
我下面的代码不起作用
错误 438/对象不支持此属性或方法
出现在 IF 开始的位置。
Option Explicit
Sub investigate()
Dim wb1 As Workbook
Dim w As String
Dim Name1 As String
Dim Path1 As String
Dim Lr As Integer
w = 2
Name1 = ThisWorkbook.Sheets("vba").Cells(w + 4, 1).Text
Path1 = ThisWorkbook.Sheets("Path").Cells(1, 2) & "Download\"
Set wb1 = Workbooks.Open(Path1 & Name1)
Lr = wb1.Sheets("Sheet1").Range("V" & Application.Rows.Count).End(xlUp).Row
If Application.WorksheetFunction.CountIf(wb1.Range("V" & Lr), ">" & 0) > 0 Then
ThisWorkbook.Sheets("vba").Cells(w + 4, 2).Value = "Overdue"
Else
ThisWorkbook.Sheets("vba").Cells(w + 4, 2).Value = "No Overdue"
End If
wb1.Close
End Sub
解决方案
我不确定你的代码会做你想做的事。如果您正在通过将重新计数保存在位置 Cells(w+ 4,2) 中来计算有多少过期以及有多少未过期,那么您将得到覆盖的值。
以下将在单元格(w+4,2)和单元格(w+5,2)中保存“过期”标题,因此它们不会重叠。在右侧的列中,您将找到这些付款的数量。
希望你喜欢
Option Explicit
Sub investigate()
Dim wb1 As Workbook
Dim w As Integer
Dim Name1 As String
Dim Path1 As String
Dim Lr As Integer
Dim overdueyes as long
Dim overdueno as long
w = 2
Name1 = ThisWorkbook.Sheets("vba").Cells(w + 4, 1).Text
Path1 = ThisWorkbook.Sheets("Path").Cells(1, 2) & "Download\"
Set wb1 = Workbooks.Open(Path1 & Name1)
Lr = wb1.Sheets("Sheet1").Range("V" & Application.Rows.Count).End(xlUp).Row
ThisWorkbook.Sheets("vba").Cells(w + 4, 2).Value = "Overdue"
ThisWorkbook.Sheets("vba").Cells(w + 5, 2).Value = "No Overdue"
for each cell in wb1.Sheets("Sheet1").range("V1:v" & lr)
if cell.value > 0 then
overdueyes = overdueyes +1
else
overdueno = overdueyes +1
end if
next
ThisWorkbook.Sheets("vba").Cells(w + 4, 3).Value = Overdueyes
ThisWorkbook.Sheets("vba").Cells(w + 5, 3).Value = Overdueno
wb1.Close
End Sub
推荐阅读
- php - OpenAPI PHP 客户端使用 anyOf 给出致命错误
- django - Django 开发服务器不一致地处理相同的 Ajax 请求
- javascript - http模块中的异步调用有问题
- elixir - 使用 Phoenix 提供多个动态图像时出现问题(一些负载,一些不负载)
- google-maps - 如何免费使用谷歌路线API
- android - Visual Studio Mac ver 8.2 Mono 6.0 Running Native Xamarin Android - “InstallPackageAssemblies”任务意外失败
- java - Java - 控制台上的记录器出现问题
- dll - mingw/msys2 构建并链接到没有版本号的 dll
- node.js - 适用于 WhatsApp 的 Twilio API
- microsoft-graph-api - Graph API 中日历所有者的电子邮件的含义