简体   繁体   English

范围的一部分格式化为文本

[英]Part of the range formatted as text

Following the answer by @Pᴇʜ in this link Merging two macros 在此链接中按照@Pᴇʜ的答案进行操作合并两个宏

I have an additional challenge. 我还有一个挑战。 Within the Named Range called "RawTab1" the column J contains values "Year" formatted as '2018 and in the column K contains values "Months" formatted as '12 在名为“ RawTab1”的命名范围内,列J包含格式为'2018的 “年份”值,在列K中包含格式为'12的值“月份” 看截图 .

I use the macro by @Pᴇʜ to copy the rng "RawTab1" to the Table called "DataTable" in the sheet called "Data" 我通过@Pᴇʜ使用宏将rng“ RawTab1”复制到工作表“ Data”中的表“ DataTable”

So my question is: 所以我的问题是:

  • Is it possible to paste these two columns formatted as numbers? 是否可以将这两列格式化为数字?

Otherwise the macro is working perfect. 否则,宏将完美工作。

Try: 尝试:

Public Sub Combined()
    Dim sht As Worksheet
    Set sht = ThisWorkbook.Worksheets("Data")
    sht.Range("A3:M3", sht.Range("A3:M3").End(xlDown)).ClearContents

    With Worksheets("Raw Data").Range("RawTab1")
        'copy everything from RawTab1 but not the first 2 rows
        Dim Crng As Range
        Set Crng = .Resize(RowSize:=.Rows.Count - 2).Offset(RowOffset:=2)
    End With

    sht.Range("A2").Resize(Crng.Rows.Count, Crng.Columns.Count).Value = _
         sht.Evaluate("IF(ISNUMBER(--" & Crng.Address(0, 0, xlA1, 1) & "),--" & Crng.Address(0, 0, xlA1, 1) & "," & Crng.Address(0, 0, xlA1, 1) & ")")

End Sub

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

相关问题 将格式化为日期的范围转换为文本 - Convert range formatted as date to text 如何使用格式化文本查找和替换单元格的一部分 - How to find and replace part of a cell with formatted text 获取范围/单元格对象的格式化文本 - Get the formatted text of a range/cell object Excel SUMIFS在一系列格式为文本的数字上 - Excel SUMIFS over a range of number formatted as text 如何仅从excel自定义格式单元格中获取文本部分 - How to get only text part from excel custom formatted cells 用部分原始文本替换单元格范围中的字符串 - replace string in cell range with part of the original text 将格式化数字范围转换为文本字符串(粘贴时保持格式,但转换为文本) - Convert range of formatted numbers to text strings (keeping formatting when pasting, but convert to text) 搜索一系列文本(如果找到),将单元格复制到电子表格的另一部分 - Search a range of text, if found, copy cells to another part of spreadsheet Excel VBA计算文本中有多少范围 - Excel VBA count how many of a range are part of a text 如果目标单元格时间(格式为 hh:mm:ss)在某个范围内,则活动单元格显示文本 - If target cell time (formatted as hh:mm:ss) is within a range, active cell displays text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM