excel vba循环通过工作表,并根据输入设置值 [英] excel vba loop through worksheets and set values according to input

查看:426
本文介绍了excel vba循环通过工作表,并根据输入设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过每个工作表循环,并将100行列A设置为输入参数的值。我希望每个工作表都调用一个输入框,并且列的值等于该输入,但发生的情况是,第一个工作表正在获取最后一个输入,而列A的所有工作表值都为空。

I'm trying to loop thru each worksheet and set 100 rows of column A to the value of an input parameter. I want each sheet to call an input box and have the column's values equal to that input but what is happening is that the 1st worksheet is getting the last input and all the sheets values for columnA are blank except for sheet 1.

Dim wkbkorigin As Workbook
Set wkbkorigin = Workbooks.Open("C:\bookB.xls")

For Each ThisWorkSheet In wkbkorigin.Worksheets  
    Subject = InputBox("Enter the 'Subject' field for " & ThisWorkSheet.Name & ":")
    For i = 1 To 100  
        Range("A2").Cells(i, 1) = Subject
    Next
Next


推荐答案

此外,没有必要循环 - 只需使用:

Also, there is no need to loop - simply use:

ThisWorkSheet.Range("A2:A100").Value = Subject

哪个会更快

这篇关于excel vba循环通过工作表,并根据输入设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆