laydaihiep
Thành viên mới

- Tham gia
- 16/1/12
- Bài viết
- 39
- Được thích
- 0
Bạn "Let'GâuGâu" đã giúp mình: https://www.giaiphapexcel.com/diendan/threads/giúp-mình-viết-macro-này-với.106206/#post-660559
Sub laydaihiep()
Dim wsNew As Worksheet, wsMain As Worksheet
Dim list_of_existing As String, Target As Range
Set wsMain = Sheets("Danh muc")
For Each Target In wsMain.Range([A10], [A60000].End(3))
If Not IsEmpty(Target) Then
On Error Resume Next
Set wsNew = ThisWorkbook.Sheets(Target.Value)
On Error GoTo 0
If Not wsNew Is Nothing Then
list_of_existing = list_of_existing & vbCrLf & Target.Value
Else
ThisWorkbook.Sheets("(1÷15)D1m").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
With Sheets(ThisWorkbook.Sheets.Count)
.Name = Target.Value
.[e12] = wsMain.Range(Target.Address).Offset(, 3).Value
End With
End If
Set wsNew = Nothing
End If
Next Target
Set wsMain = Nothing
If Len(list_of_existing) > 0 Then
MsgBox "Cap nhat cac sheet moi da thanh cong !"
End If
End Sub
Nhưng mình cần chỉnh sửa đoạn code tạo sheet trong vùng chọn ở trên từ U10-V10, U10 và V10 mình chọn bất kỳ. Bác pro nào giúp mình với. Thank!
Sub laydaihiep()
Dim wsNew As Worksheet, wsMain As Worksheet
Dim list_of_existing As String, Target As Range
Set wsMain = Sheets("Danh muc")
For Each Target In wsMain.Range([A10], [A60000].End(3))
If Not IsEmpty(Target) Then
On Error Resume Next
Set wsNew = ThisWorkbook.Sheets(Target.Value)
On Error GoTo 0
If Not wsNew Is Nothing Then
list_of_existing = list_of_existing & vbCrLf & Target.Value
Else
ThisWorkbook.Sheets("(1÷15)D1m").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
With Sheets(ThisWorkbook.Sheets.Count)
.Name = Target.Value
.[e12] = wsMain.Range(Target.Address).Offset(, 3).Value
End With
End If
Set wsNew = Nothing
End If
Next Target
Set wsMain = Nothing
If Len(list_of_existing) > 0 Then
MsgBox "Cap nhat cac sheet moi da thanh cong !"
End If
End Sub
Nhưng mình cần chỉnh sửa đoạn code tạo sheet trong vùng chọn ở trên từ U10-V10, U10 và V10 mình chọn bất kỳ. Bác pro nào giúp mình với. Thank!