ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Help to add new sheet in a workbook with a condition (https://www.excelbanter.com/excel-worksheet-functions/123848-help-add-new-sheet-workbook-condition.html)

[email protected]

Help to add new sheet in a workbook with a condition
 
I am new with macros and i am not able to solve this problem. If
someone could help me , I would really appreciate that .

1- I have 3 tabs in this worksheet with the data
- Tabs A , Master Data and refernce Table
2- Suppose column K in the tab " Master Data " has a record or number,
they can be repeated as the new data us added every month.

3- Reference table has the list of the same data record ( numbers ) .

Now the situation is if there is a new record in the column K of the
master data sheet the Macro should do the following.

a- Check for the record in the refeence table , if doent exist
then add the recor in the reference
table

b- create another sheet same as the sheet " A" (duplicate of
A)
b- Plug the new record number in the cell B2 of the new sheet

c - Copy the row 8 from ( D8 to O8 ) in the new sheet from (D8 to
O8)from sheet A
Thanks


JLatham

Help to add new sheet in a workbook with a condition
 
I believe this code will do what you want. It needs to go into the Master
Data worksheet's code. To get to that place, right-click on the [Master
Data] sheet tab and choose [View Code] from the list. Cut and paste the code
below into that module and then close the Visual Basic Editor.

You did not say what column to copy the new entry into on the Reference
Table sheet, so I used column K for it also.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim newEntry As Variant ' unknown type
Dim SearchRange As Range
Dim SearchResult As Variant

If Target.Column < 11 Then ' not column K
Exit Sub
End If
If Target.Cells.Count 1 Then ' not a single cell
Exit Sub
End If
'value in 1 cell in column K changed
Application.EnableEvents = False
newEntry = Target.Value
Set SearchRange = Sheets("Reference Table").Range("K:K")
On Error Resume Next ' will error if it is a new number
SearchResult = SearchRange.Find(What:=newEntry, _
After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Err = 0 Then
'a match was found, no work to do
Application.EnableEvents = True
Exit Sub
End If
'here if it is a new value
Err.Clear
On Error GoTo 0
Application.ScreenUpdating = False
Sheets("Reference Table").Range("K" & Rows.Count). _
End(xlUp).Offset(1, 0) = newEntry
Sheets("A").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Range("B2") = newEntry
Sheets("Master List").Select
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

" wrote:

I am new with macros and i am not able to solve this problem. If
someone could help me , I would really appreciate that .

1- I have 3 tabs in this worksheet with the data
- Tabs A , Master Data and refernce Table
2- Suppose column K in the tab " Master Data " has a record or number,
they can be repeated as the new data us added every month.

3- Reference table has the list of the same data record ( numbers ) .

Now the situation is if there is a new record in the column K of the
master data sheet the Macro should do the following.

a- Check for the record in the refeence table , if doent exist
then add the recor in the reference
table

b- create another sheet same as the sheet " A" (duplicate of
A)
b- Plug the new record number in the cell B2 of the new sheet

c - Copy the row 8 from ( D8 to O8 ) in the new sheet from (D8 to
O8)from sheet A
Thanks




All times are GMT +1. The time now is 08:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com