Vba code to compare columns in different sheets

Nawin616

New Member
Joined
Oct 27, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
HI Friends ,

I'm looking for a little help in Vba macro.

I have two sheets ( category ) which has values like CURRENT ASSETS ,NON CURRENT ASSETS, CURRENT LIABILITIES ,NON CURRENT LIABILITIES , PROFIT LOSS Etc..

in the other sheet (Balance sheet) in column A i have CURRENT ASSETS ,NON CURRENT ASSETS, CURRENT LIABILITIES . How do i compare the two sheets (Category & Balance sheet) and add data that are available in Category sheet and not available in Balance sheet.. the values should be added to column A in Balance sheet

Thanks in advance.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this code:
VBA Code:
With Worksheets("Category")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
cats = .Range(.Cells(1, 1), .Cells(lastrow, 1))
End With
With Worksheets("Balance")
lastrowb = .Cells(Rows.Count, "A").End(xlUp).Row
bals = .Range(.Cells(1, 1), .Cells(lastrowb, 1))
indi = lastrowb + 1
 For i = 1 To lastrow
  If cats(i, 1) <> "" Then
   fnd = False
   For j = 1 To lastrowb
    If cats(i, 1) = bals(j, 1) Then
     fnd = True
     Exit For
    End If
   Next j
   If Not (fnd) Then
    .Range(.Cells(indi, 1), .Cells(indi, 1)) = cats(i, 1)
    indi = indi + 1
   End If
  End If
 Next i
 
End With
This is my understanding of what you want but you requirements are not absolutely clear
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,708
Members
452,994
Latest member
Janick

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