My code not working.. Please help!!

Aashna

New Member
Joined
Jun 17, 2015
Messages
19
Hello,

Please help me with this. I have a workbook with three tabs Raw Data, Master File and Category.



  • There is a button 'Populate Sheet Data' embedded on the raw data sheet, upon clicking this button the master file should get filled with the data (as shown in 2nd table below) and should show a message box 'Process Finished'.
  • Raw data sheet has 3 columns:

Data1: consists of fixed values
Article #: each article belong to one category or all (total categories are 4)
Category: Specifies to which category each article belongs (if it says all that particular article should appear in all 4 categories in master file sheet.


My code:

Code:
[/B][/COLOR]
[FONT=Verdana]Sub ArticleCategoryTransfer()[/FONT]
Dim j As Long, i As Long, lastRow1 As Long, DestLast As Long
Dim sh_data, sh_target As Worksheet
Dim AllCategory As String
Dim CategoryCount As Long


Set sh_data = Sheets("Raw Data")
Set sh_target = Sheets("Master File")
Set sh_category = Sheets("Category")


DestLast = sh_target.Range("A" & Rows.Count).End(xlUp).Row + 1
lastRow1 = sh_data.UsedRange.Rows.Count
AllCategory = "All Category"
CategoryCount = sh_category.UsedRange.Rows.Count


'This loop populates data for individual category (category that aren't "All")


    For i = 2 To lastRow1
    
        If sh_data.Cells(i, 3).Value <> AllCategory Then
            sh_target.Cells.Range("G" & DestLast) = sh_data.Cells(i, 2).Value
            sh_target.Cells.Range("J" & DestLast) = sh_data.Cells(i, 3).Value
            DestLast = sh_target.Range("G" & Rows.Count).End(xlUp).Row + 1
        End If


    Next i


'This loop populates data for "All"


For i = 2 To lastRow1
 
    For j = 2 To CategoryCount
   
        If sh_data.Cells(i, 3).Value = AllCategory Then
            sh_target.Cells.Range("G" & DestLast) = sh_data.Cells(i, 2).Value
            sh_target.Cells.Range("J" & DestLast) = sh_sites.Cells(j, 1).Value
            DestLast = sh_target.Range("G" & Rows.Count).End(xlUp).Row + 1
        End If


    Next j


Next i


MsgBox "Process Finished!"

 [COLOR=#333333]End Sub[/COLOR][COLOR=#000080][B]

Thank You,
Aashna

<tbody>
</tbody>
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Below are look-alike of my workbook:
Raw Data
ABC
1Data1Article #Category
2A2301
3A824
4A461all
5A6613
6A641all
7A6682

<tbody>
</tbody>


Master File: Current status of output
ABCDEFGHIJK
1
2
3
4Data2Data3Data1Data4Data5Data6Article #Data7Data8CategoryDelivery Date
5A2301
6A824
7A461all
8A6613
9A641all
10A6682

<tbody>
</tbody>




























  • Data in columns Data2, Data3, Data5 & Data7 should get auto-fill as the data in these columns remain stagnant.
______________________________________________________________________________________________________




Master File: Desired Output
ABCDEFGHIJK
1
2
3
4Data2Data3Data1Data4Data5Data6Article #Data7Data8CategoryDelivery Date
5cbAd230e18/14/2015
6cbAd461e18/14/2015
7cbAd641e18/14/2015
8cbAd668e28/14/2015
9cbAd461e28/14/2015
10cbAd641e28/14/2015
11cbAd661e38/14/2015
12cbAd461e38/14/2015
13cbAd641e38/14/2015
14cbAd82e48/14/2015
15cbAd461e48/14/2015
16cbAd641e48/14/2015

<tbody>
</tbody>


<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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