简体   繁体   English

Excel VBA-Find(Cell.Value)和格式问题

[英]Excel VBA - Issues with Find(Cell.Value) and formatting

I have several columns of data with various headings that I would like to narrow down and organize according to their headings. 我有几列具有不同标题的数据,我想根据它们的标题缩小范围并进行组织。 Right now I'm accomplishing my task by copying the data under each heading on my source sheet, finding the same heading on a destination sheet, and pasting under the new heading. 现在,我通过复制源工作表中每个标题下的数据,在目标工作表中找到相同的标题并粘贴在新标题下来完成任务。 My code is: 我的代码是:

For Each Cell In NewData 'where NewData is the range with all of the headings
    Range(Cell.Offset(1, 0), Cell.Offset(1, 0).End(xlDown)).Copy
    Worksheets("Total").Activate
    Worksheets("Total").Rows(2).Find(Cell.Value).End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    On Error Resume Next
'error handling skips data columns in sheet 1 that are not found in sheet 2
Next Cell

I have two examples of my problem: 我有两个问题的例子:

1). 1)。 Some of my data headings are "5/64", "6/64", and "7/64", which when pasted into Excel returns as a date format. 我的某些数据标题为“ 5/64”,“ 6/64”和“ 7/64”,将其粘贴到Excel中后会以日期格式返回。 The Cell.Text returns, for example, "May-64" instead of "5/64", while the Cell.Value returns "5/1/1964". Cell.Text返回例如“ May-64”而不是“ 5/64”,而Cell.Value返回“ 5/1/1964”。 This is fine with me, as long as its consistent throughout, but my sub is entering data from the heading "5.5" into the column that should only be "5/64" (or since I'm using Cell.Value, "5/1/1964"). 只要在整个过程中保持一致,这对我来说就很好,但是我的子对象正在将标题“ 5.5”中的数据输入到应该仅为“ 5/64”的列中(或者因为我使用的是Cell.Value,所以“ 5” / 1/1964“)。

2). 2)。 Similarly to the first example, I have two data columns "Total Protein" and "Total Protein(NIR)", where data from "Total Protein" is being pasted under the "Total Protein(NIR)" heading. 与第一个示例类似,我有两个数据列“ Total Protein”和“ Total Protein(NIR)”,其中“ Total Protein”中的数据被粘贴在“ Total Protein(NIR)”标题下。

For both of these examples I'm guessing there's a problem with how I am handling the Cell.Value. 对于这两个示例,我都在猜测如何处理Cell.Value会出现问题。 Using Cell.Text instead doesn't work either; 使用Cell.Text也不起作用。 this skips the "May-64" headings entirely. 这会完全跳过“ May-64”标题。 Any tips? 有小费吗?

Socii had the right idea - specifying LookAt:=xlWhole fixed the issue. Socii有一个正确的想法-指定LookAt:= xlWhole解决了该问题。 Thanks for the responses 感谢您的回应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM