Create new sheet

AbuFawaz

New Member
Joined
Sep 21, 2017
Messages
9
so I have 2 sheets and need to create a third one as follows:

Sheet1
IDName Code
A001AC1
A002BC2
A003CC3
A004DC4

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


Sheet2
CodeID_2Data
C1B0012
C1B0023
C1B0034
C1B0043
C1B0052
C2B0061
C2B0072
C3B0082
C3B0092
C3B0105
C4B0114
C4B0126
C4B0132
C4B0141
C4B0152
C4B0163
C4B0175
C4B0185

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>

I need sheet3 to be created as:
ID ID_2 Data


Many thanks in advance.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about
Code:
Sub CreateSht()
   Dim Cl As Range
   Dim Ary As Variant
   Dim i As Long
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   Ary = Ws2.Range("A1").CurrentRegion
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("C2", Ws1.Range("C" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, -2).Value
      Next Cl
      For i = 1 To UBound(Ary)
         If .exists(Ary(i, 1)) Then Ary(i, 1) = .Item(Ary(i, 1))
      Next i
   End With
   Sheets("Sheet3").Range("A1").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
   Sheets("Sheet3").Range("A1").Value = "ID"
End Sub
 
Upvote 0
This is perfect if i run it on Sheet3, is there anyway to make the code create Sheet3 and show the result there ?
Yet thank you very much (y)
 
Upvote 0
How about
Code:
Sub CreateSht()
   Dim Cl As Range
   Dim Ary As Variant
   Dim i As Long
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   Ary = Ws2.Range("A1").CurrentRegion
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("C2", Ws1.Range("C" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, -2).Value
      Next Cl
      For i = 1 To UBound(Ary)
         If .exists(Ary(i, 1)) Then Ary(i, 1) = .Item(Ary(i, 1))
      Next i
   End With
   Sheets("Sheet3").Range("A1").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
   Sheets("Sheet3").Range("A1").Value = "ID"
End Sub
Will the changes be made if I do it one either of the two sheets?
Is there a way to put it on autoupdate?
 
Upvote 0
@AbuFawaz
Try
Code:
Sub CreateSht()
   Dim Cl As Range
   Dim ary As Variant
   Dim i As Long
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   ary = Ws2.Range("A1").CurrentRegion
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("C2", Ws1.Range("C" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, -2).Value
      Next Cl
      For i = 1 To UBound(ary)
         If .exists(ary(i, 1)) Then ary(i, 1) = .Item(ary(i, 1))
      Next i
   End With
   If Not Evaluate("isref(Sheet3!A1)") Then
      Sheets.Add(, Sheets(Sheets.Count)).Name = "Sheet3"
   End If
   Sheets("Sheet3").Range("A1").Resize(UBound(ary), UBound(ary, 2)).Value = ary
   Sheets("Sheet3").Range("A1").Value = "ID"
End Sub
@ethanscott
Please do not "Hijack" other peoples threads. You need to start a thread of your own.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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