简体   繁体   中英

Excel VBA - automatic if Cell A equals X then copy and paste in Cell B

I currently have the below:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B2,B11,D11")) Is Nothing Then
        Application.EnableEvents = False
        For Each C In Target
            If Not Intersect(C, Range("B2,B11,D11")) Is Nothing And Not C.HasFormula Then _
                C.Value = UCase(C.Value)
        Next C
        Application.EnableEvents = True
    End If
End Sub

I need to add another macro to basically do:

If G6 = N/A then copy and paste into H6, otherwise do nothing.

How should I add this in?

Based on your question I'm not sure how you want to include this in your code, also your code opens an if statement inside your for loop but closes it outside, I doubt this is correct.. anyway here is the code to copy the data to H6:

If (ActiveSheet.Range("G6").Value = "N/A") Then
    ActiveSheet.Range("H6").Value = ActiveSheet.Range("G6").Value
Else
    'do nothing     
End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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