Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 直到列为空为止_Excel_Vba - Fatal编程技术网

Excel 直到列为空为止

Excel 直到列为空为止,excel,vba,Excel,Vba,我的VBA中的do INTILL函数有问题。由于某些原因,它不会进入下一行,并且在列单元格为空时不会停止。请帮忙 Sub rollforward() Dim myfile As String Dim myfolder As String myfolder = "\\tps-san\Share\ Accounting\Inventory\2019 Inv\Inventory Rollforward\11 Nov" myfile = Dir(myfolder & "\*.xlsx")

我的VBA中的do INTILL函数有问题。由于某些原因,它不会进入下一行,并且在列单元格为空时不会停止。请帮忙

Sub rollforward()

Dim myfile As String
Dim myfolder As String

myfolder = "\\tps-san\Share\ Accounting\Inventory\2019 Inv\Inventory Rollforward\11 Nov"

myfile = Dir(myfolder & "\*.xlsx")

Do While myfile <> ""
Workbooks.Open Filename:=myfolder & "\" & myfile
myfile = Dir
Loop

Workbooks("Beg Balance").Activate

Dim i As Integer
i = 17

Do Until IsEmpty(ActiveCell)

If Cells(i, 2) = "0011" Or "0021" Or "0705" Or "20" Or "21" Then Cells(i, 2) = "0020"
If Cells(i, 2) = "9999" Then Cells(i, 2) = "9011"
If Cells(i, 2) = "9650" Or "9599" Or "9972" Or "9940" Then Cells(i, 2) = "9031"
If Cells(i, 2) = "9230" Or "9059" Then Cells(i, 2) = "9059"
If Cells(i, 2) = "4212" Or "7212" Then Cells(i, 2) = "9212"
If Cells(i, 2) = "9214" Then Cells(i, 2) = "9214"
If Cells(i, 2) = "9408" Then Cells(i, 2) = "9415"
If Cells(i, 2) = "9916" Then Cells(i, 2) = "9500"
If Cells(i, 2) = "9215" Then Cells(i, 2) = "9535"
If Cells(i, 2) = "9055" Then Cells(i, 2) = "9737"
If Cells(i, 2) = "9706" Or "2037" Then Cells(i, 2) = "9770"
If Cells(i, 2) = "7901" Or "7903" Then Cells(i, 2) = "9905"
If Cells(i, 2) = "9262" Then Cells(i, 2) = "9915"

Loop
子前滚()
将myfile设置为字符串
将myfolder设置为字符串
myfolder=“\\tps san\Share\Accounting\Inventory\2019 Inv\Inventory Rollforward\11月11日”
myfile=Dir(myfolder&“\*.xlsx”)
当我的文件“”时执行此操作
工作簿。打开文件名:=myfolder&“\”&myfile
myfile=Dir
环
工作簿(“求平衡”)。激活
作为整数的Dim i
i=17
直到IsEmpty(ActiveCell)为止
如果单元格(i,2)=“0011”或“0021”或“0705”或“20”或“21”,则单元格(i,2)=“0020”
如果单元格(i,2)=“9999”,则单元格(i,2)=“9011”
如果单元格(i,2)=“9650”或“9599”或“9972”或“9940”,则单元格(i,2)=“9031”
如果单元格(i,2)=“9230”或“9059”,则单元格(i,2)=“9059”
如果单元(i,2)=“4212”或“7212”,则单元(i,2)=“9212”
如果单元(i,2)=“9214”,则单元(i,2)=“9214”
如果单元格(i,2)=“9408”,则单元格(i,2)=“9415”
如果单元格(i,2)=“9916”,则单元格(i,2)=“9500”
如果单元格(i,2)=“9215”,则单元格(i,2)=“9535”
如果单元格(i,2)=“9055”,则单元格(i,2)=“9737”
如果单元格(i,2)=“9706”或“2037”,则单元格(i,2)=“9770”
如果单元格(i,2)=“7901”或“7903”,则单元格(i,2)=“9905”
如果单元格(i,2)=“9262”,则单元格(i,2)=“9915”
环

不要使用活动单元格,先尝试查找最后一个值,然后将其分配给变量并使用for循环。这应该对你有用

只需更改您的工作表和您正在查看的列。 最后一行的查找方法与正在查看的列中按Ctrl+Shift+End的查找方法相同

Dim ws As Worksheet
Dim lastRow As Integer, i As Integer

Set ws = ThisWorkbook.Sheets(1)

lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

For i = 1 To lastRow

    'Do loop things here

Next

您没有在每个循环中将
1
添加到
i
,也没有激活另一个单元格进行测试,因此它正在测试同一个单元格。而是找到最后一个有值的单元格,然后使用for循环。不要依赖于
ActiveCell
。有关如何查找最后一行的信息,请参阅。因此,在结尾处,我应该添加i=i+1@ScottCranerNo更多内容,我建议在循环之前查找结尾,并使用for循环。
如果单元格(i,2)=“0011”或“0021”或“0705”
等。。。不会做你认为它会做的事。