Mr Kid,
terima kasih ya Mr Kid, cuman kenapa ya saldo awal muncul angka di kolom E, 
seharusnya kolom D dan E untuk saldo awal kosong. cuman kalau sebelumnya saya 
beri tanda petik (") di kolom D dan E maka waktu diproses macronya baru bisa 
berjalan dengan sempurna.
Mohon koreksinya Mr Kid.
terima kasih,
ASL

 To: belajar-excel@yahoogroups.com
From: belajar-excel@yahoogroups.com
Date: Wed, 27 May 2015 06:07:47 +1000
Subject: Re: [belajar-excel] Menyatukan 2 atau 3 baris menjadi 1 baris data

   
 Hai Ahmad,


Kalau dilihat dari previewnya, sepertinya pengen ada tambahan syarat pokok 
kolom D (kolom dikirinya yang kasus lalu, sesuaikan dengan keadaan nyatanya 
bila ada kolom kosong diantaranya yang tak tampak) yang seperti kolom E.
 

 Coba fokus pada blok IF dalam prosedur yang lalu :
public Sub kopi()       'tambahin explicit nya scope ah supaya mudah membacanya
    Dim baris As double, x As long
    Dim wadah As String
    For x = cells(rows.count,3).end(xlup).row To 7 Step -1

       if Cells(x, 5).Value<>0 then                                  'poin 1 
diperjelas keterangannya -> kolom E <> 0

              if Cells(x, 1).Value = 0 Then                                     
'kondisi dalam poin 1 alias poin 1.>.  -> kolom A = 0

                     wadah = Cells(x, 3).Value & " " & wadah
                    baris = Cells(x, 5).Value
                    Cells(x, 3).Value = vbnullstring
                     Cells(x, 5).Value = vbnullstring
             endif

      elseif Cells(x, 1).Value <> 0 then                          'poin 2     
-> kolom E=0 DAN kolom A <> 0

                   Cells(x, 3).Value = Cells(x, 3).Value & " " & wadah
                  wadah = vbnullstring
                  Cells(x, 5).Value = baris

      else                                                                   
'poin 3     -> kolom E=0  DAN kolom A = 0
              wadah = Cells(x, 3).Value & " " & wadah
              Cells(x, 3).Value = vbnullstring

     endif
   Next x
End Sub

 
Kondisi baru : (poin 1.5)

      Kolom D memiliki karakteristik seperti kolom E 

 
       if Cells(x, 5).Value<>0 then                                  'poin 1 
diperjelas keterangannya -> kolom E <> 0

              if Cells(x, 1).Value = 0 Then                                     
'kondisi dalam poin 1 alias poin 1.>.  -> kolom A = 0

                     wadah = Cells(x, 3).Value & " " & wadah
                    baris = Cells(x, 5).Value
                    Cells(x, 3).Value = vbnullstring
                     Cells(x, 5).Value = vbnullstring
             endif

       elseif Cells(x, 4).Value<>0 then                                  'poin 
1.5 diperjelas keterangannya -> kolom D <> 0
              if Cells(x, 1).Value = 0 Then                                     
'kondisi dalam poin 1 alias poin 1.>.  -> kolom A = 0

                     wadah = Cells(x, 3).Value & " " & wadah
                    baris = Cells(x, 4).Value
                    Cells(x, 3).Value = vbnullstring
                    Cells(x, 4).Value = vbnullstring
             endif


      elseif Cells(x, 1).Value <> 0 then                          'poin 2     
-> kolom E=0 DAN kolom A <> 0

                   Cells(x, 3).Value = Cells(x, 3).Value & " " & wadah
                  wadah = vbnullstring
                  Cells(x, 5).Value = baris

      else                                                                   
'poin 3     -> kolom E=0  DAN kolom A = 0
              wadah = Cells(x, 3).Value & " " & wadah
              Cells(x, 3).Value = vbnullstring

     endif


 Sampai disini terjadi masalah berikut :
a. nilai dalam variabel 'baris' tidak diketahui sumbernya, yaitu dari nilai 
kolom E (akibat mengerjakan poin 1) atau dari kolom D (akibat mengerjakan poin 
1.5)


 b. penulisan nilai yang disimpan dalam variabel bernama 'baris' adalah ke 
kolom E saja (lihat yang merah)

 

 Solusi untuk masalah untuk kasus :

 a. disediakan sebuah variabel penyimpan nomor kolom sumber nilai yang diambil. 
Jadi tugasnya menyimpan nilai 5 kalau mengambil nilai kolom E karena 
mengerjakan poin 1, atau menyimpan nilai 4 kalau mengambil nilai kolom D karena 
mengerjakan poin 1.5. Maka diblok poin 1 dan blok poin 1.5 nantinya akan diberi 
baris kode pengisian nilai 5 atau 4 tersebut.


 b. karena proses penulisan menggunakan posisi nomor row dan nomor column 
seperti Cells(x, 5).Value yang berarti di cells row ke-x di column 5, berarti 
angka 5 pada baris tersebut bisa diganti dengan variabel penyimpan nilai sumber 
kolom (5 atau 4) yang menjadi solusi poin a diatas tadi.

 

 Proses penerapan solusi :

 1. butuh sebuah variabel baru penyimpan nilai 5 atau 4

 > butuh deklarasi variabel baru yang datatype untuk numerik bilangan bulat 
 > saja, bisa byte, integer, atau long

 > misal dipilih datatype Long supaya native dengan bit applikasi office yang 
 > digunakan yang 32 bit

 > nama variabelnya misal diberi nama lKolomSumber

 > bunyi deklarasinya :

        dim lKolomSumber as long


 2. setiap blok poin diberi baris kode untuk set nilai 5 atau 4 sesuai kondisi 
ke variabel baru tersebut

 > blok poin 1 dulu  -> berdasar kolom E <> 0

     * poin 1 menggunakan kolom E alias kolom nomor 5 sebagai kondisi

     * berarti nilai variabel lKolomSumber diblok ini harus diisi dengan nilai 5

     * prosesnya ditulis tepat setelah mengambil nilai dari kolom E

     * berarti, setelah kode berbunyi :
                   baris = Cells(x, 5).Value

       diberi proses pengisian nilai 5 ke variabel lKolomSumber dengan bunyi 
berikut :

                    lKolomSumber=5


 > blok poin 1.5 -> berdasar kolom D <> 0
     * poin 1 menggunakan kolom D alias kolom nomor 4 sebagai kondisi

     * berarti nilai variabel lKolomSumber diblok ini harus diisi dengan nilai 4

     * prosesnya ditulis tepat setelah mengambil nilai dari kolom D

     * berarti, setelah kode berbunyi :
                   baris = Cells(x, 4).Value

       diberi proses pengisian nilai 4 ke variabel lKolomSumber dengan bunyi 
berikut :

                   lKolomSumber=4


 3. Penulisan isi variabel bernama 'baris' ke suatu cells dilakukan sesuai 
kolom sumbernya

 > kode penulisan nilai yang sudah ada dalam prosedur berbunyi :
                    Cells(x, 5).Value = baris
 > pada kode di atas, kolom sumbernya ditunjukkan dengan angka 5

 > berarti bagian angka 5 itulah yang harus diganti dengan variabel penyimpan 
 > nomor kolom sumbernya (nama variabelnya lKolomSumber kan ya)

 > berarti bunyi kodenya akan menjadi :
                    Cells(x, lKolomSumber).Value = baris

 

 Jadi prosedur yang sudah dikembangkan akan menjadi :

public Sub kopi()       'tambahin explicit nya scope ah supaya mudah membacanya

    Dim baris As double, x As long
    Dim wadah As String
    dim lKolomSumber as long
    'private cop as object    'dumb private object
    For x = cells(rows.count,3).end(xlup).row To 7 Step -1

       if Cells(x, 5).Value<>0 then                                  ''poin 1 
diperjelas keterangannya -> kolom E <> 0

              if Cells(x, 1).Value = 0 Then                                     
'kondisi dalam poin 1 alias poin 1.>.  -> kolom A = 0

                     wadah = Cells(x, 3).Value & " " & wadah
                    baris = Cells(x, 5).Value
                    lKolomSumber =5
                    Cells(x, 3).Value = vbnullstring
                     Cells(x, 5).Value = vbnullstring
             endif


       elseif Cells(x, 4).Value<>0 then                                  "poin 
1.5 diperjelas keterangannya -> kolom D <> 0
              if Cells(x, 1).Value = 0 Then                                     
'kondisi dalam poin 1 alias poin 1.>.  -> kolom A = 0

                     wadah = Cells(x, 3).Value & " " & wadah
                    baris = Cells(x, 4).Value
                    lKolomSumber =4
                    Cells(x, 3).Value = vbnullstring
                    Cells(x, 4).Value = vbnullstring
             endif


      elseif Cells(x, 1).Value <> 0 then                          ''poin 2     
-> kolom E=0 DAN kolom A <> 0

                   Cells(x, 3).Value = Cells(x, 3).Value & " " & wadah
                  wadah = vbnullstring
                  Cells(x, lKolomSumber ).Value = baris

      else                                                                   
''poin 3     -> kolom E=0  DAN kolom A = 0
              wadah = Cells(x, 3).Value & " " & wadah
              Cells(x, 3).Value = vbnullstring

     endif

     

    Next x

End Sub



;)


 Wassalam,

 Kid

 




 

 


 
 

 
 
 
 


  • Re: [belajar... Nang Agus nanga...@gmail.com [belajar-excel]
    • RE: [be... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
    • RE: [be... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
    • RE: [be... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • Re:... Toby kenzo tobyke...@yahoo.co.id [belajar-excel]
      • Re:... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
      • Re:... Nang Agus nanga...@gmail.com [belajar-excel]
      • RE:... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • Re:... Toby kenzo tobyke...@yahoo.co.id [belajar-excel]
      • Re:... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
      • RE:... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • Re:... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
      • RE:... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • RE:... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • Re:... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
      • RE:... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]
      • Re:... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
  • RE: [belajar... Ahmad Syaifullah Lubis syaiful...@hotmail.com [belajar-excel]

Kirim email ke