Hello,
Please help me with this. I have a workbook with three tabs Raw Data, Master File and Category.
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:
<tbody>
</tbody>
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>