基于两个工作簿之间的数据匹配和粘贴数据

如何解决基于两个工作簿之间的数据匹配和粘贴数据

我要处理的情况是,在第一列中有一张表格,其中有帐号,在第五列中有金额,在第七列中有“ F”或“ P”。帐号与第一列中另一个工作簿上的帐号匹配。如果在表的第七列中(在源工作簿中有一个“ F”,则应将值复制,匹配并粘贴到目标工作簿的第四列中的同一行上。如果有“ P,”的值应匹配并粘贴到目标工作簿的第五列的同一行上。该代码可以工作,但不会区分F或P,而是将所有值粘贴到两个列中。

import React from 'react';
import { Link } from 'react-router-dom';

const Navigation = (props) => {
  function toggleBurgerMenu() {
    document.querySelector('.navbar-menu').classList.toggle('is-active');
  }

  return (
    <nav className="navbar" role="navigation" aria-label="main navigation">
      <div className="navbar-brand">
        <Link to="/" className="navbar-item">React App</Link>

        <a role="button" className="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasic"
          onClick={toggleBurgerMenu}>
          <span aria-hidden="true"></span>
          <span aria-hidden="true"></span>
          <span aria-hidden="true"></span>
        </a>
      </div>

      <div id="navbarBasic" className="navbar-menu">
        <div className="navbar-start">
          <Link to="/about" className="navbar-item" onClick={toggleBurgerMenu}>About</Link>
          <Link to="/contact" className="navbar-item" onClick={toggleBurgerMenu}>Contact</Link>
          <Link to="/notes" className="navbar-item" onClick={toggleBurgerMenu}>Notes</Link>
        </div>
      </div>
    </nav>
  );
}

export default Navigation;

解决方法

如何完全重写。

阅读评论以进行解释

'compare text (ignore case)
option compare text 

dim source_wb as workbook
dim dest_wb as workbook

dim source_ws as worksheet
dim dest_ws as worksheet

'set workbooks/sheets
set source_wb = workbooks("HF Pricing Template1")
set source_ws = source_wb.worksheets("Table")

set dest_wb = workbooks("Book1")
set dest_ws = dest_wb.worksheets("Sheet1")

dim source_lr as integer
dim dest_lr as integer

'get last row of data in each sheet for column 1 (the account numbers)
'checks for account number list in column "a" change where applicable
source_lr = source_ws.cells(rows.count,"M").end(xlup).row
dest_lr = dest_ws.cells(rows.count,"A").end(xlup).row


'this starts checking for account numbers at row 2 change where applicable
for source_row = 2 to source_lr
    ''this start checking for account numbers at row 2 change where applicable
    for dest_row = 2 to dest_lr
        'check if account numbers match
        ' change column as applicable 
        if source_ws.cells(source_row,"M") = dest_ws.cells(dest_row,"A") then
            'if column 7  in source contains p then copy to column 4 in dest ws
            'change column where applicable
            if source_ws.cells(source_row,"S") = "p" then
                dest_ws.cells(dest_row,"D") = source_ws.cells(source_row,"R")
                exit for
  
            'if column 7  in source contains f then copy to column 5 in dest ws
            ' change column where applicable
            elseif source_ws.cells(source_row,"S") = "f" then
                dest_ws.cells(dest_row,"E") = source_ws.cells(source_row,"R")
                exit for
            end if
        end if
    next dest_row
next source_row

请注意-我现在不在Windows计算机上,无法对此进行测试,但是它应该可以正常工作。

,
Dim source_wb As Workbook
Dim dest_wb As Workbook

Dim source_ws As Worksheet
Dim dest_ws As Worksheet

'set workbooks/sheets
Set source_wb = Workbooks("HF Pricing Template1")
Set source_ws = source_wb.Worksheets("Tables")

Set dest_wb = Workbooks("Book1")
Set dest_ws = dest_wb.Worksheets("Sheet1")

Dim source_lr As Integer
Dim dest_lr As Integer

'get last row of data in each sheet for column 1 (the account numbers)
'checks for account number list in column "a" change where applicable
source_lr = source_ws.Cells(Rows.Count,"M").End(xlUp).Row
dest_lr = dest_ws.Cells(Rows.Count,"A").End(xlUp).Row


'this starts checking for account numbers at row 2 change where applicable
For source_row = 5 To source_lr
''this start checking for account numbers at row 2 change where applicable
For dest_row = 2 To dest_lr
    'check if account numbers match
    ' change column as applicable
    If source_ws.Cells(source_row,"M") = dest_ws.Cells(dest_row,"A") Then
        'if column 7  in source contains p then copy to column 4 in dest ws
        'change column where applicable
        If source_ws.Cells(source_row,"S") = "P" Then
            dest_ws.Cells(dest_row,"D") = source_ws.Cells(source_row,"M")
            Exit For
        'if column 7  in source contains f then copy to column 5 in dest ws
        ' change column where applicable
        ElseIf source_ws.Cells(source_row,"S") = "F" Then
            dest_ws.Cells(dest_row,"E") = source_ws.Cells(source_row,"M")
            Exit For

        End If
     End If
   Next
 Next

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res