Check condition and copy data?

adamasmay

New Member
Joined
Dec 30, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Form file as attached.

I want to check column AI & column AJ data have same or not (If found some rows blank = same)

If found not match , I want to check column AccRole that value = Insured or Payer.
- If column AccRole = Insured ---> I want to copy data from column LFNAME to column AccountFile.
- If column AccRole = Payer ---> I want to copy data from column Name payer to column AccountFile.


Remark : But If in column AccountFile have data already , I don't have to do anything about it.

Please guide me about it.
 

Attachments

  • input.JPG
    input.JPG
    84.6 KB · Views: 7
  • output.JPG
    output.JPG
    91.7 KB · Views: 7

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I want output in same sheet input.

I separate output sheet for show output data only.
 
Upvote 0
I want output in same sheet input.

I separate output sheet for show output data only.

Add one sheet more, pretty much like this :

Untitled.png


add one button to it, just call it "Validate" (or what ever you want)

Tab Developer > (on controls category) select insert > choose Button from Form Control

Untitled2.png



click New and put this code :

VBA Code:
Sub Button1_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
   
    Dim oWs As Worksheet
    Dim lRow As Long
    Dim i As Long
   
    Set oWs = ThisWorkbook.Sheets("YOUR INPUT SHEET NAME")
   
    lRow = oWs.UsedRange.Rows.Count
   
    For i = 2 To lRow
        If oWs.Range("AI" & i) <> vbNullString And oWs.Range("AJ" & i) <> vbNullString Then
            If oWs.Range("AX" & i) = "Payer" Then
                If oWs.Range("AM" & i) = vbNullString Then
                    oWs.Range("AM" & i) = oWs.Range("BB" & i)
                    oWs.Range("AM" & i).Font.Color = vbRed
                End If
            Else
                If oWs.Range("AM" & i) = vbNullString Then
                    oWs.Range("AM" & i) = oWs.Range("BC" & i)
                    oWs.Range("AM" & i).Font.Color = vbRed
                 End If
            End If
        End If
    Next i
   
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
   
    Set oWs = Nothing
End Sub

change SHEET NAME to your Input sheet name.
 
Last edited:
Upvote 0
Add one sheet more, pretty much like this :

View attachment 55363

add one button to it, just call it "Validate" (or what ever you want)

Tab Developer > (on controls category) select insert > choose Button from Form Control

View attachment 55364


click New and put this code :

VBA Code:
Sub Button1_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
  
    Dim oWs As Worksheet
    Dim lRow As Long
    Dim i As Long
  
    Set oWs = ThisWorkbook.Sheets("YOUR INPUT SHEET NAME")
  
    lRow = oWs.UsedRange.Rows.Count
  
    For i = 2 To lRow
        If oWs.Range("AI" & i) <> vbNullString And oWs.Range("AJ" & i) <> vbNullString Then
            If oWs.Range("AX" & i) = "Payer" Then
                If oWs.Range("AM" & i) = vbNullString Then
                    oWs.Range("AM" & i) = oWs.Range("BB" & i)
                    oWs.Range("AM" & i).Font.Color = vbRed
                End If
            Else
                If oWs.Range("AM" & i) = vbNullString Then
                    oWs.Range("AM" & i) = oWs.Range("BC" & i)
                    oWs.Range("AM" & i).Font.Color = vbRed
                 End If
            End If
        End If
    Next i
  
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
  
    Set oWs = Nothing
End Sub

change SHEET NAME to your Input sheet name.

VBA Code:
Sub Button1_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    
    Dim oWs As Worksheet
    Dim lRow As Long
    Dim i As Long
    
    Set oWs = ThisWorkbook.Sheets("YOUR INPUT SHEET NAME")
    
    lRow = oWs.UsedRange.Rows.Count
    
    For i = 2 To lRow
        If oWs.Range("AI" & i) <> vbNullString And oWs.Range("AJ" & i) <> vbNullString Then
            If oWs.Range("AM" & i) = vbNullString Then
                If oWs.Range("AX" & i) = "Payer" Then
                    oWs.Range("AM" & i) = oWs.Range("BB" & i)
                Else
                    oWs.Range("AM" & i) = oWs.Range("BC" & i)
                End If
                
                oWs.Range("AM" & i).Font.Color = vbRed
            End If
        End If
    Next i
    
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
    Set oWs = Nothing
End Sub

Sorry, i change the code little bit
 
Upvote 0
I want add 1 requirement , Some row in column AM have text -

If column AI have data but column AJ have data = - -----> I want to check column AccRole and write data same condition above.

Please guide me more for solve it.
 

Attachments

  • Capture.JPG
    Capture.JPG
    82.5 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,203,739
Messages
6,057,075
Members
444,903
Latest member
Mavericx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top