本文介绍了如何在单元格中附加已存在文本的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图用单元格中已经存在的文本附加文本。但是我的下面的代码正在替换text.please帮助我在vba中我是新的。我该怎么做才能附加文本,我应该使用哪个命令? 我的尝试: Sub micro1() lr = ThisWorkbook.Worksheets( sheet3)。Cells(Rows.Count, A )。结束(xlUp)。 i = 2 lr a = ThisWorkbook.Worksheets( sheet3)。单元格( 2 , 1 )a = a + 3 ThisWorkbook.Worksheet s(a).Activate lr1 = ThisWorkbook.Worksheets(a).Cells(Rows.Count, B)。结束(xlUp)。 j = 2 要 lr1 nm = ThisWorkbook.Worksheets( 4 )。单元格(j, 2 ) 如果 nm = General Ward 然后 ThisWorkbook .Worksheets( 3 )。单元格( 2 , 6 ).Value = ThisWorkbook.Worksheets( 4 )。Cells(j, 3 )。 结束 如果 下一步 下一步 结束 Sub 解决方案 将数据分配给单元格时,您需要读取旧数据并将其与新数据一起附加。例如,以下内容会将一些文本附加到单元格A1 ActiveSheet.Cells( 1 , 1 )。值= ActiveSheet.Cells( 1 , 1 )。值+ 其他数据 i was trying to append the text with already existing text in cell.but my below code is replacing the text.please help me i am new one in vba.what should i do to append the text,which command i should use?What I have tried:Sub micro1() lr = ThisWorkbook.Worksheets("sheet3").Cells(Rows.Count, "A").End(xlUp).Row For i = 2 To lr a = ThisWorkbook.Worksheets("sheet3").Cells(2, 1) a = a + 3 ThisWorkbook.Worksheets(a).Activate lr1 = ThisWorkbook.Worksheets(a).Cells(Rows.Count, "B").End(xlUp).Row For j = 2 To lr1 nm = ThisWorkbook.Worksheets(4).Cells(j, 2) If nm = "General Ward" Then ThisWorkbook.Worksheets(3).Cells(2, 6).Value = ThisWorkbook.Worksheets(4).Cells(j, 3).Value End If Next NextEnd Sub 解决方案 When assigning the data to the cell, you need to read the old data and append it along with the new data. For example the following would append some text to cell A1ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(1, 1).Value + " additional data" 这篇关于如何在单元格中附加已存在文本的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 11:36