Excel将整行复制到其他工作表(Excel copy whole row to other sheet)
任何人都可以帮我兑现这些东西!? 我想使用Sheet1的第7列中的每个值作为参数,并将其复制到Sheet2,如果Sheet2具有此参数,则使用sheet1的第1列中的值在Sheet2的第30列中搜索,如果它符合条件,然后将sheet2中的整行复制到新的sheet3
Sub test() ' Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Sheet3" ' FinalRow = Cells(Rows.Count, 1).End(xlUp).Row LastRow_Sheet1 = Worksheets("Sheet1").UsedRange.Rows.Count LastRow_Sheet2 = Worksheets("Sheet2").UsedRange.Rows.Count For x = 2 To LastRow_Sheet1 po_number = Worksheets("Sheet1").Cells(x, 7).Value site_name = Worksheets("Sheet1").Cells(x, 1).Value Worksheets("Sheet2").Activate For y = 2 To LastRow_Sheet2 If po_number <> Worksheets("Sheet1").Cells(y, 1).Value Then If InStr(1, CStr(site_name), Worksheets("Sheet2").Cells(y, 30)) >= 1 Then Range("Cells(y, 1):Cells(y,31)").Copy Sheets("Sheet3").Select NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 Cells(NextRow, 1).Select ActiveSheet.Paste End If End If Next Next End Sub
正如Scott所建议的那样,我将代码改为如下,Sub test()
LastRow_Sheet1 = Worksheets("Sheet1").UsedRange.Rows.Count LastRow_Sheet2 = Worksheets("Sheet2").UsedRange.Rows.Count For x = 2 To 2 po_number = Worksheets("Sheet1").Cells(x, 7).Value site_name = Worksheets("Sheet1").Cells(x, 1).Value For y = 2 To 20000 If po_number <> Worksheets("Sheet2").Cells(y, 1).Value Then With Worksheets("Sheet2") ' I ASSUME THIS IS THE SHEET YOU WANT TO WORK WITH. CHANGE AS NECESSARY If InStr(1, CStr(site_name), .Cells(y, 30)) >= 1 Then Range(Cells(y, 1), Cells(y, 31)).Copy nextRow = Sheets("Sheet3").Cells(Sheets("Sheet3").Rows.Count, 1).End(xlUp).Row + 1 Sheets("Sheet3").Range("A" & nextRow).PasteSpecial 'You may need to change this. I am not sure what range you were wanting to paste to End If End With End If Next Next
结束子
但没有任何复制到Sheet3大声笑...而且,我想知道什么是
Sheets("Sheet3").Range("A" & nextRow).PasteSpecial
这一行代表什么?非常感谢!
Could any one help me to dubug this things!? I want to use each value in 7th column of Sheet1 as parameters, and copy it to Sheet2, and if Sheet2 has this parameters, then use values in 1st column of sheet1 to search in Column 30th of Sheet2, and if it meet the criteria, then copy whole row in sheet2 to new sheet3
Sub test() ' Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Sheet3" ' FinalRow = Cells(Rows.Count, 1).End(xlUp).Row LastRow_Sheet1 = Worksheets("Sheet1").UsedRange.Rows.Count LastRow_Sheet2 = Worksheets("Sheet2").UsedRange.Rows.Count For x = 2 To LastRow_Sheet1 po_number = Worksheets("Sheet1").Cells(x, 7).Value site_name = Worksheets("Sheet1").Cells(x, 1).Value Worksheets("Sheet2").Activate For y = 2 To LastRow_Sheet2 If po_number <> Worksheets("Sheet1").Cells(y, 1).Value Then If InStr(1, CStr(site_name), Worksheets("Sheet2").Cells(y, 30)) >= 1 Then Range("Cells(y, 1):Cells(y,31)").Copy Sheets("Sheet3").Select NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 Cells(NextRow, 1).Select ActiveSheet.Paste End If End If Next Next End Sub
As suggested by Scott, I change the code as below, Sub test()
LastRow_Sheet1 = Worksheets("Sheet1").UsedRange.Rows.Count LastRow_Sheet2 = Worksheets("Sheet2").UsedRange.Rows.Count For x = 2 To 2 po_number = Worksheets("Sheet1").Cells(x, 7).Value site_name = Worksheets("Sheet1").Cells(x, 1).Value For y = 2 To 20000 If po_number <> Worksheets("Sheet2").Cells(y, 1).Value Then With Worksheets("Sheet2") ' I ASSUME THIS IS THE SHEET YOU WANT TO WORK WITH. CHANGE AS NECESSARY If InStr(1, CStr(site_name), .Cells(y, 30)) >= 1 Then Range(Cells(y, 1), Cells(y, 31)).Copy nextRow = Sheets("Sheet3").Cells(Sheets("Sheet3").Rows.Count, 1).End(xlUp).Row + 1 Sheets("Sheet3").Range("A" & nextRow).PasteSpecial 'You may need to change this. I am not sure what range you were wanting to paste to End If End With End If Next Next
End Sub
But nothing copy to Sheet3 lol ... And also, I am wondering what
Sheets("Sheet3").Range("A" & nextRow).PasteSpecial
this line stands for?Many thanks!
原文:https://stackoverflow.com/questions/39920808
最满意答案
这很简单:
public function actorAction($id, Request $request, Application $app)
Silex(实际上是Symfony2的HttpFoundation)将命名参数从url传递给函数的参数并使用相同的名称。
您还应该检查参数转换器,以便控制器获取id引用的对象(或数组),而不是普通id。
It's as simple as this:
public function actorAction($id, Request $request, Application $app)
Silex (Symfony2's HttpFoundation, actually) passes the named parameters from the url to the function's argument with the same name.
You should also check out the parameter converters so your controller gets the object (or array) the id refers to, and not the plain id.
相关问答
更多-
我在symfony食谱里找到了答案...... http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html $app->match('{url}', function($url){ //do legacy stuff })->assert('url', '.+'); I found the answer within the symfony cookbook... http://symfony.com/doc/2.0/co ...
-
我正在使用Silex中的翻译服务,并且从http://silex.sensiolabs.org/doc/providers/translation.html的使用示例中偶然复制到我的代码中。 因此,上面的路由定义被设置中先前定义的定义所捕获。 $app->get('/{_locale}/{message}/{name}', function ($message, $name) use ($app) { return $app['translator']->trans($message, array( ...
-
试试这个,让我们知道它是怎么回事。 $routes = Cache::has('routes') ? Cache::get('routes') : $model->getInstance()->getRoutes(); if (!Cache::has('routes')) { Cache::add('routes', $routes, 120); } 替换为您的“$ routes = $ model-> getInstance() ...
-
就我所知,路由组件并不支持这种开箱即用的方式。 我仔细研究了一下代码,得出结论认为添加这样的路线将会很困难。 路由工作的方式是在匹配完成之前每条路由都被注册,因此路由必须存在。 这意味着不能有“通配符路线”。 我不知道你是否考虑到了这一点,但你可以随时通过“真实”获取参数传递尽可能多的信息: /print/template?optional1=arg&optional2=arg 这可以解决你的问题,并且可以不做任何修改。 你可以通过另一种方式来处理这个问题,就是注册一个事件前,自己查看请求并修改它。 例如, ...
-
这很简单: public function actorAction($id, Request $request, Application $app) Silex(实际上是Symfony2的HttpFoundation)将命名参数从url传递给函数的参数并使用相同的名称。 您还应该检查参数转换器,以便控制器获取id引用的对象(或数组),而不是普通id。 It's as simple as this: public function actorAction($id, Request $request, App ...
-
PHP Silex路由本地化(PHP Silex routing localization)[2022-08-16]
我认为您可以使用mount函数委派本地检测: 您为要支持的每个本地安装路由,但它们重定向到同一个控制器: $app->mount('/en/', new MyControllerProvider('en')); $app->mount('/fr/', new MyControllerProvider('fr')); $app->mount('/de/', new MyControllerProvider('de')); 现在本地可以是您的控制器的属性: class MyContro ... -
您需要flush控制器集合。 mount它们后,请调用: $app->flush(); You need to flush the controller collection. After you mount them, call this: $app->flush();
-
Silex:动态表格(Silex : Dynamic forms)[2022-11-19]
我设法做了我想做的事。 我创建了补充表格,要求填写每个“父”对象。 所以除了我的类型表单,我现在选择一个选择表单,允许我选择Region,然后选择Country,然后选择State。 I managed to do what i wanted. I created supplementary forms, asking for filling each of the "parent" objects. So in addition to my Types forms, i now have a select ... -
这是一个迟到的答案,但我自己遇到了这个问题,但事实证明Dan的解决方案与ngView指令上的ngAnimate类冲突,并且显示了视图但是将立即应用ng-leave动画并隐藏视图用他的动态路由打开。 我在这里找到了完美的解决方案,它在1.1.5 +中可用 在$routeProvider , templateUrl值可以是一个函数,并且传递路由参数: app.config(function ($routeProvider) { $routeProvider .when('/:page', { ...
-
我已经将问题缩小到我的vendor文件夹中的一个坏库,但我无法确定它是哪一个。 我将正确工作的供应商文件夹复制到破碎的文件夹中,一切都开始有效。 一旦我知道确切的问题,我会更新这个答案。 I've narrowed the problem down to a bad library in my vendors folder, though I can't be sure which one it is. I copied my correctly working vendors folder to my b ...