Membandingkan 2 kolom data di Ms Excel

27 10 2008

Kebiasaan berkutat di jaringan, trus ada temen minta dibuatin macro untuk mempercepat pekerjaanya, terpaksa deh dikerjain sekalian belajar. Pasti atas bantuan om google – search kesana kemari, ga ketemu juga macro yang cocok untuk kasus seperti ini. Akhirnya corat-coret lagi algoritma untuk bikin program seperti ini.

Pertama-tama bandingkan kolom A (Date) dan D (Date), kemudian disesuaikan antara kolom A dan D sehingga berpasangan.

Buat macro seperti biasa dan sisipkan code seperti dibawah ini :

Sub Miss()
'
' Miss Macro
' Macro recorded 11/09/2008 by Wahyu Kusnandar
'
' Keyboard Shortcut: Ctrl+m
'
Application.ScreenUpdating = False
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Range("A2").Select
TotalRow = ActiveSheet.UsedRange.Rows.Count
Range("D2").Select

For Row = 2 To TotalRow Step 1
   ActiveCell.FormulaR1C1 = "=ISNA(MATCH(RC[-3],R2C5:R5000C5,FALSE))"
   ActiveCell.Offset(1, 0).Select
Next Row

Range("A2:D10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Range("D2").Select
TotalRow = ActiveSheet.UsedRange.Rows.Count
Range("H2").Select

For Row = 2 To TotalRow Step 1
   ActiveCell.FormulaR1C1 = "=ISNA(MATCH(RC[-4],R2C1:R5000C1,FALSE))"
   ActiveCell.Offset(1, 0).Select
Next Row

Range("D2:H10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("H2").Select
TotalRow = ActiveSheet.UsedRange.Rows.Count

For Row = 2 To TotalRow Step 1
   If ActiveCell.Value = True Then
      ActiveCell.EntireRow.Insert
      Columns("H:H").ClearContents
      Exit For
   End If
   ActiveCell.Offset(1, 0).Select
Next Row

End Sub

Selanjutnya silahkan mengatur jumlah baris (R2C5:R5000C5) sesuai dengan data yang akan dibandingkan.

– selamat mencoba –

Advertisement

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.