VBA Check if Cell is Empty & Add to Database Sheet

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hi Excel Gurus,

I'm working on an macro project and almost done. I'm just having a problem on this: I have 2 excel sheet, one is working file and the other is database. What the macro needs to do is to check the cell with blank category (in working file) and add below column data in the database (next blank cell).

1) Merged Name
2) Addr
3) Code


*Working File Excel Sheet (Working tab)

RefMerged NameName 1Name 2AddrCodeQuantityCategory
001Sean SmithSeanSmithLA1115000Included
002Ian GropIanGropSA1254500Excluded
003Lea MasonLeaMasonAM1164000For Review
004Tricia JavierTriciaJavierMT1023000
005Den BertheDenBertheBE1152500Excluded
006Mae LimMaeLimAB1362000
007Oscar ChardeOscarChardeCH1401000

<tbody>
</tbody>

*Database Excel Sheet (Database tab)

AccountData 1Merged NameData 2AddrxCodexxxxxCategory
Sean SmithLA111Included
Ian GropSA125Excluded
Lea MasonAM116For Review
Den BertheBE115Excluded

<tbody>
</tbody>

Any help will be much appreciated.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Code:
Sub unknownymous()
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("sheet1")
   Set Ws2 = Sheets("sheet2")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("C2", Ws1.Range("C" & Rows.Count).End(xlUp))
         v = Join(Application.Index(Cl.Resize(, 5).Value, 1, Array(1, 3, 5)), "|")
         .Item(v) = Cl.Offset(, 7).Value
      Next Cl
      For Each Cl In Ws2.Range("B2", Ws2.Range("B" & Rows.Count).End(xlUp))
         v = Join(Application.Index(Cl.Resize(, 5).Value, 1, Array(1, 4, 5)), "|")
         Cl.Offset(, 6).Value = .Item(v)
      Next Cl
   End With
End Sub
 
Upvote 0
This is amazing Fluff.

One thing, what if I want to add the Quantity from Working File and put it in the column next to Code in Database File?
 
Upvote 0
How about
Code:
Sub unknownymous()
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   Dim Cl As Range
   Dim v As String
   
   Set Ws1 = Sheets("sheet1")
   Set Ws2 = Sheets("sheet2")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("B2", Ws2.Range("B" & Rows.Count).End(xlUp))
         v = Join(Application.Index(Cl.Resize(, 5).Value, 1, Array(1, 4, 5)), "|")
         .Item(v) = .Item(v) + Cl.Offset(, 5).Value
      Next Cl
      For Each Cl In Ws1.Range("C2", Ws1.Range("C" & Rows.Count).End(xlUp))
         v = Join(Application.Index(Cl.Resize(, 5).Value, 1, Array(1, 3, 5)), "|")
         Cl.Offset(, 5).Value = .Item(v)
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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