我要处理的情况是,在第一列中有一张表格,其中有帐号,在第五列中有金额,在第七列中有“ 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;
答案 0 :(得分:0)
如何完全重写。
阅读评论以进行解释
'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计算机上,无法对此进行测试,但是它应该可以正常工作。
答案 1 :(得分:0)
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