循环查找名称然后执行函数vba excel [英] Looping through columns finding name Then doing a Function vba excel

查看:88
本文介绍了循环查找名称然后执行函数vba excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel我有6个不同的名称作为变量。变量是动态的。每次我执行此功能时,它们最终会出现在不同的行中。有人可以帮助我如何通过这些名称循环。找出哪个名称是哪个。然后根据名称的含义执行不同的计算。名称总是以A列结尾。它们最终排在不同的行中。所以我想知道如何做一个看起来像这样的函数/宏.......如果name = Anna d1 = b1 * c1。如果名字=哈利d1 = b1 + c1 .......谢谢你们。我是excel的新手。



I have a excel Where i Have 6 different names as variables . The varibles are dynamic . They end up in different rows everytime i do this function . Can someone please help me on how to go about Looping through these names . Finding out which name is which . then performing a different calculation depending on what the "name " is . The names always end up in Column A . They just end up in different rows . So i would like to know how to do a function /macro that looks like this ....... If name = Anna d1=b1*c1 . If name = Harry d1 = b1+c1 ....... Thank you guys . I am new to excel .

<br />
Name <br />
Number<br />
Number <br />
 <br />
Anna <br />
       36.476833<br />
        7.96618557<br />
 if name = Anna Number "times Number" <br />
<br />
Eric <br />
17.451147<br />
5.80342102<br />
if name = Eric Number + Number <br />
<br />
Ronald<br />
21.125067<br />
6.45224857<br />
<br />
If name =  Ronald Number "divided"By Number <br />
<br />
Roxanne<br />
12.071469<br />
2.55927372<br />
 <br />
Harry <br />
0<br />
30.1705704<br />
 <br />
Vallerie<br />
11.67783<br />
0<br />
 <br />
Wally <br />
0<br />
6.81271219<br />
 <br />

推荐答案

您好b $ b

对于i = 2到100< ------这个值是在第1列上查找的范围

如果是Sheet(?)。Cells(i,1)=Anna然后< ------执行以下代码,其中我是真的。

Sheet(?)。Cells(i,4).Value = Sheet(?)。Cells(i,2) ).Value + Sheet(?)。Cells(i,3).Value

结束如果



*在这里添加你的下一个if语句

*表(?)?必须用您正在使用的工作表名称替换,即:工作表(1)

下一页
Hi
For i = 2 To 100 <------ this value is the range to lookup on column 1
If Sheet(?).Cells(i, 1) = "Anna" Then <------ execute the following code where i is true.
Sheet(?).Cells(i, 4).Value = Sheet(?).Cells(i, 2).Value +Sheet(?).Cells(i, 3).Value
End If

* Add your next if statements here
* Sheet(?) The ? must be replaced by the sheet name you are using ie: Sheet(1)
Next i


这篇关于循环查找名称然后执行函数vba excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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