在Excel中将新字符串附加到单元格

时间:2015-08-11 09:14:12

标签: excel vba excel-vba

我试过这个,但它不能正常工作:

Sub macro1()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim LR As Long
With ActiveSheet
    LR = .Cells(.Rows.Count, "C").End(xlUp).Row
End With

For r = 2 To LR

p = Application.Match(Cells(r, 3), Sheets("Input").Range("C:C"), 0)

If IsError(p) Then GoTo nextr:

Cells(r, 4).Value = .Value & ",newsletter" '***here***


nextr:
Next r

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

如果我在标有 此处 的行上使用以下内容:

Cells(r,4) = "Y"

它有效,所以我猜我做错了吗?

1 个答案:

答案 0 :(得分:0)

只是拼出答案并很好地格式化:

Option Explicit

Sub macro1()
Dim p As Double
Dim LR As Long
Dim r As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

LR = ActiveSheet.Cells(ActiveSheet.Rows.Count, "C").End(xlUp).Row

For r = 2 To LR
    p = Application.Match(Cells(r, 3), Sheets("Input").Range("C:C"), 0)
    If Not IsError(p) Then
        ActiveSheet.Cells(r, 4).Value = ActiveSheet.Cells(r, 4).Value & ",newsletter" '***here***
    End If
Next r

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub