首页 \ 问答 \ Excel将整行复制到其他工作表(Excel copy whole row to other sheet)

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
更新时间:2022-07-07 11:07

最满意答案

这很简单:

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 ...
  • 我认为您可以使用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();
  • 我设法做了我想做的事。 我创建了补充表格,要求填写每个“父”对象。 所以除了我的类型表单,我现在选择一个选择表单,允许我选择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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)