Các nhãn và các tên trong công thức

  • Thread starter handung107
  • Ngày gửi
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Đây cũng là một add-in về Tên và nhãn, các bạn sẽ có trên Menu Tools khi chép Name List.xla vào thư mục add-in. Với add-in này, bạn có thể xoá các tên, biết các tên nào không hợp lệ, những Link, những tên trong Worksheet, những tên trong Workbook, bạn có thể đến vùng, dãy có tên trong danh sách bằng nút Go to
 
Khóa học Quản trị dòng tiền
W

WhoamI

Cao cấp
handung107 nói:
WhoamI viết thêm chức năng Insert / Name /Paste / Paste Link nhé,
Chị ơi! không biết có phải do máy em chỉ dùng office 2000 nên không có Insert / Name /Paste / Paste Link hay sao đó mà em chỉ thấy có Paste List thôi?.
Chức năng Paste List này tương tự như cái utility trong Excel utilities mà em đã nói ở dưới. Giúp liệt kê tất cả các Refers To của các Define Name được định nghĩa trong Workbook.
handung107 nói:
Còn phần nữa là Tên cục bộ (sử dụng cho riêng Sheet đó) và Tên toàn cục (sử dụng cho các Sheet trong Workbook) nữa, chúng ta sẽ kết luận phần này.,
Hi! cái này thì em vẫn chưa biết đây!
 
Sửa lần cuối:
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Xin lỗi, đó là Paste List, chứ không phải Paste Link, WhoamI nói vậy là đúng rồi. Cám ơn em
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Nghĩa là có bao nhiêu tên được đặt trong Workbook sẽ được liệt kê trong hộp Name và muốn chọn hay xoá tuỳ ý. Đây cũng là một ý nên để tập trung trong bài "Tên và nhãn". Maica nếu phát triển thêm có thể đưa thành File add-in, và hoặc đưa vào Menu, hoặc Right-Click...Add-in NameList.xla cũng giống như File này, các bạn tha hồ nghiên cứu và sử dụng
 
W

WhoamI

Cao cấp
handung107 nói:
Còn phần nữa là Tên cục bộ (sử dụng cho riêng Sheet đó) và Tên toàn cục (sử dụng cho các Sheet trong Workbook) nữa, chúng ta sẽ kết luận phần này.
Nhưng có cách nào để tạo tên sử dụng cho các Workbook không chị? Vì khi em tham chiếu đến Wokkbook khác thường thì phải tham chiếu trực tiếp vùng dữ liệu làm công thức dài lắm ạ!
VD:
- Trên file COSODULIEU đã đặt tên cho cùng dữ liệu sheet1!A3:E6 là DMNV chẳng hạn.
- Trên 1 file khác em có công thức : =Vlookup('COSODULIEU'sheet1!$A$3:$E$6;$D2;Columns($A$3:$D$6);0)
Em muốn thay 'COSODULIEU'sheet1!$A$3:$E$6;$D2 = DMNV thì phải làm cách nào ạ? Em thử gõ cả tên Workbook trước name đó cũng không được?
 
Sửa lần cuối:
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Giới thiệu Add-in Name Lister

Name Lister, tên đầy đủ là J-Walk Name Lister, có trong PUP 6. Với Add-in này, bạn có thể liệt kê tất cả các tên trong Workbook. Ngoài ra, bạn có thể chọn theo từng Option để được DS liệt kê theo từng loại như sau :
1/ Những tên ở cấp độ Workbook
2/ Những tên ở cấp độ Sheet (dành cho những tên đặt riêng cho những Sheet đặc hiệu)
3/ Những tên ẩn (hidden) : Những tên này thưỡng không thể hiện ở hộp Name của Insert / Name /Defeine
4/Những tên Link (Linked Names) tham chiếu đến những Workbook khác
5/ Những tên không hợp lệ : (Bad names), những tên này cần được xoá bỏ
Add -In này sẽ giúp bạn :
- Xoá các tên không hợp lệ, cũng như những tên nào bạn muốn xoá
-Khi bạn chọn tên trong hộp tên và Click nút Go To, bạn sẽ đến ngay vùng dãy có tên đó, mà không cần đóng hộp thoại Name Lister lại
Bạn nào đã có PUP (Power Utility Pak) thì sẽ có add-in này, nếu chưa có, bạn có thể Down riêng lẻ add-in này để sử dụng cho chức năng này tuỳ ý
 
levanduyet

levanduyet

Welcome
16/10/04
537
19
18
HCM
my.opera.com
Name Lister
Phần I
Đây là đọan mã trong module của Name Lister
Ngòai ra còn có UserForm1 (bài sau)
Option Explicit
Public Const PUPNAME As String = "Power Utility Pak"
Public Const APPNAME As String = "Name Lister"
'Các bạn chú ý khai báo kiểu biến này rất hay và tiện trong lập trình
Type NameType
TheName As String
TheIndex As Long
RefersTo As String
SheetLevel As Boolean
DefinedIn As String
Hidden As Boolean
Linked As Boolean
Bad As Boolean
BySheet As String
End Type

Public AllNames() As NameType
Public NameCount As Long

Sub NameLister()
Dim Msg As String, Ans As Long
CheckAddIn
If ActiveSheet Is Nothing Then Exit Sub
If ActiveWorkbook.Names.Count = 0 Then
MsgBox "The active workbook contains no names.", vbInformation, APPNAME
Exit Sub
End If
If ActiveWorkbook.ProtectStructure Then
Msg = "The active workbook's structure is protected." & vbCrLf & "You can view names, but you will not be able to delete any names." & vbCrLf & vbCrLf & "Continue?"
Ans = MsgBox(Msg, vbInformation + vbYesNo, APPNAME)
If Ans = vbNo Then
Exit Sub
Else
UserForm1.DeleteButton.Enabled = False
UserForm1.DeleteAll.Enabled = False
End If
End If
UserForm1.Show
End Sub

Sub GetAllNames()
' Add names to the AllNames array
Dim n As Name
Dim s As String
Dim wks As Worksheet
Dim pn As String
ReDim Preserve AllNames(1 To ActiveWorkbook.Names.Count)
NameCount = 0

For Each n In ActiveWorkbook.Names
NameCount = NameCount + 1
AllNames(NameCount).TheName = n.Name
AllNames(NameCount).TheIndex = n.Index
AllNames(NameCount).RefersTo = n.RefersTo
If TypeName(n.Parent) = "Workbook" Then
AllNames(NameCount).SheetLevel = False
Else
AllNames(NameCount).SheetLevel = True
End If
AllNames(NameCount).DefinedIn = n.Parent.Name
AllNames(NameCount).Hidden = Not n.Visible
AllNames(NameCount).Linked = (n.RefersTo Like "*[[]*") Or (n.RefersTo Like "*\*")
AllNames(NameCount).Bad = n.RefersTo Like "*REF!*"
On Error Resume Next
If AllNames(NameCount).Bad Then
AllNames(NameCount).BySheet = ""
Else
pn = n.RefersToRange.Parent.Name
If Err = 0 Then AllNames(NameCount).BySheet = pn Else AllNames(NameCount).BySheet = "(none)"
End If
On Error GoTo 0
Next n
On Error GoTo 0
End Sub
Private Sub CheckAddIn()
On Error GoTo CloseMe
If Workbooks("pup6.xla").Sheets(1).Range("A1") = "Utility" Then Exit Sub
CloseMe:
ThisWorkbook.Close
End Sub
Private Function StripSheetName(s)
' Removes the sheet name from a reference
StripSheetName = Right(s, Len(s) - InStr(s, "!"))
End Function


Chúc các bạn thành công.
Lê Văn Duyệt
levanduyet@gmail.com
 
levanduyet

levanduyet

Welcome
16/10/04
537
19
18
HCM
my.opera.com
Name Lister
Phần II
Đây là đọan mã của UserForm1
Namelister.gif
[/IMG]
Option Explicit
Dim WarningWasShown As Boolean
Dim Output As Worksheet
Dim EventsEnabled As Boolean

Private Sub UserForm_Activate()
Dim i As Long
DoEvents
GetAllNames
EventsEnabled = True
obAll_Click
LabelRefersTo.Font.Bold = False
End Sub

Private Sub UserForm_Initialize()
Dim sht As Object
EventsEnabled = False
Me.Caption = APPNAME
Label1.Caption = "Names in " & ActiveWorkbook.Name
For Each sht In ActiveWorkbook.Sheets
ComboSheetList.AddItem sht.Name
Next sht
With ComboSheetList
.AddItem "(no sheet)"
.Value = ActiveSheet.Name
.Enabled = False
End With
With LabelRefersTo
.Caption = "Retrieving names..."
.Font.Bold = True
End With
DoEvents
End Sub

Private Sub ListBox1_Click()
Dim i As Long
If Not EventsEnabled Then Exit Sub
On Error Resume Next
For i = 1 To NameCount
If AllNames(i).TheName = ListBox1.Value Then
With LabelRefersTo
.Caption = AllNames(i).RefersTo
.ControlTipText = .Caption
End With
ListBox1.ControlTipText = ListBox1.Value
If AllNames(i).Hidden Then UnhideButton.Enabled = True Else UnhideButton.Enabled = False
If AllNames(i).Bad Then GotoButton.Enabled = False Else GotoButton.Enabled = True
Exit For
End If
Next i
If Err <> 0 Then
With LabelRefersTo
.Caption = ""
.ControlTipText = .Caption
End With
End If
If ListBox1.Value = "(none)" Then
GotoButton.Enabled = False
DeleteButton.Enabled = False
DeleteAll.Enabled = False
Else
GotoButton.Enabled = True
If Not ActiveWorkbook.ProtectStructure Then
DeleteButton.Enabled = True
DeleteAll.Enabled = True
End If
End If
On Error GoTo 0
End Sub

Private Sub obAll_Click()
' Show all names
Dim i As Long
ListBox1.Clear
DoEvents
ComboSheetList.Enabled = False
UnhideButton.Enabled = False
For i = 1 To NameCount
ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub

Private Sub obWorkbook_Click()
' Show workbook level names
Dim i As Long
ListBox1.Clear
DoEvents
ComboSheetList.Enabled = False
UnhideButton.Enabled = False
For i = 1 To NameCount
If Not AllNames(i).SheetLevel Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub

Private Sub obSheetLevel_Click()
' Show sheet level names
Dim i As Long
ComboSheetList.Enabled = False
UnhideButton.Enabled = False
ListBox1.Clear
DoEvents
For i = 1 To NameCount
If AllNames(i).SheetLevel Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub

Private Sub ComboSheetList_Change()
Dim i As Long
Dim ShtName As String
If Not EventsEnabled Then Exit Sub
ListBox1.Clear
DoEvents
ShtName = ComboSheetList.Value
ComboSheetList.ControlTipText = ComboSheetList.Value
If ShtName = "(no sheet)" Then ShtName = "(none)"
For i = 1 To NameCount
If AllNames(i).BySheet = ShtName Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub

Private Sub obBySheet_Click()
Call ComboSheetList_Change
With ComboSheetList
.Enabled = True
.SelStart = 0
.SelLength = 100
.SetFocus
End With
End Sub

Private Sub obHidden_Click()
' Show hidden names
Dim i As Long
ListBox1.Clear
DoEvents
ComboSheetList.Enabled = False
UnhideButton.Enabled = True
For i = 1 To NameCount
If AllNames(i).Hidden Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then
ListBox1.AddItem "(none)"
UnhideButton.Enabled = False
End If
ListBox1.ListIndex = 0
End Sub

Private Sub obLinked_Click()
' Show linked names
Dim i As Long
ListBox1.Clear
DoEvents
ComboSheetList.Enabled = False
UnhideButton.Enabled = False
For i = 1 To NameCount
If AllNames(i).Linked Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub


Chúc các bạn thành công
Lê Văn Duyệt
 
levanduyet

levanduyet

Welcome
16/10/04
537
19
18
HCM
my.opera.com
Name Lister
Phần III
Private Sub obBad_Click()
' Show erroneous names
Dim i As Long
ListBox1.Clear
DoEvents
ComboSheetList.Enabled = False
UnhideButton.Enabled = False
For i = 1 To NameCount
If AllNames(i).Bad Then ListBox1.AddItem AllNames(i).TheName
Next i
If ListBox1.ListCount = 0 Then ListBox1.AddItem "(none)"
ListBox1.ListIndex = 0
End Sub

Private Sub DeleteButton_Click()
Dim ListPlace As Long
Dim DisplayedSheet As Long
Dim Ans As Integer
Dim NameIndex As Long
' Deletes the selected name

' Show the warning only one time
If Not WarningWasShown Then
WarningWasShown = True
Ans = MsgBox("Caution!" & vbCrLf & vbCrLf & "Deleting a name that is used in a formula will cause the formula to return an error.", vbCritical + vbOKCancel, APPNAME)
If Ans = vbCancel Then Exit Sub
End If

ListPlace = ListBox1.ListIndex 'remember list item
DisplayedSheet = ActiveSheet.Index 'remember active sheet number

' add a new blank worksheet at the beginning, so that there is no
' possibility that there is a similar name on the active sheet
On Error Resume Next
Application.ScreenUpdating = False
Worksheets.Add before:=Sheets(1)
NameIndex = ActiveWorkbook.Names(ListBox1.Value).Index
With ActiveWorkbook.Names(NameIndex)
.Visible = True ' this handles cases of "bad" hidden names that can't be deleted
.Delete ' delete the name
End With
Application.DisplayAlerts = False
Worksheets(1).Delete 'delete the new sheet
Application.DisplayAlerts = True
Sheets(DisplayedSheet).Select 're-activate the active sheet
Application.ScreenUpdating = True

If Err = 0 Then
If NameCount = 1 Then ' last name was deleted
With ListBox1
.Clear
.AddItem "(none)"
.ListIndex = 0
End With
MsgBox "The active workbook contains no more names.", vbInformation, APPNAME
Unload Me: Exit Sub
Else
' adjust the array
Call GetAllNames

If obAll Then Call obAll_Click
If obWorkbook Then Call obWorkbook_Click
If obSheetLevel Then Call obSheetLevel_Click
If obHidden Then Call obHidden_Click
If obLinked Then Call obLinked_Click
If obBad Then Call obBad_Click
If obBySheet Then Call obBySheet_Click
End If
Else
MsgBox "Cannot delete that name." & vbCrLf & vbCrLf & "It may be an invalid name. If the name is visible you may be able to delete it using Excel's Define Name dialog box.", vbInformation, APPNAME
End If
If NameCount = 0 Then ReportButton.Enabled = False

If ListPlace = ListBox1.ListCount Then ListPlace = ListPlace - 1
ListBox1.ListIndex = ListPlace
ListBox1.SetFocus
On Error GoTo 0
End Sub

Private Sub DeleteButton_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
' This handles fast button clicks, which are otherwise ignored
DeleteButton_Click
End Sub

Private Sub DeleteAll_Click()
Dim Ans As String
Dim Msg As String
Dim NameCount As Long
Dim NameIndex As Long
Dim i As Long, DisplayedSheet As Long

NameCount = ListBox1.ListCount
DisplayedSheet = ActiveSheet.Index 'remember active sheet number

Msg = ""
If Not WarningWasShown Then
WarningWasShown = True
Msg = Msg & "Deleting a name that is used in a formula will cause your formula to return an error." & vbCrLf
If NameCount = 1 Then
Msg = Msg & "Deleting this name cannot be undone." & vbCrLf & vbCrLf
Else
Msg = Msg & "Deleting these names cannot be undone." & vbCrLf & vbCrLf
End If
Else
If NameCount = 1 Then
Msg = Msg & "OK to delete this name?"
Else
Msg = Msg & "OK to delete these " & NameCount & " names?"
End If
End If

Ans = MsgBox(Msg, vbInformation + vbYesNo, APPNAME)
If Ans <> vbYes Then Exit Sub

' add a new blank worksheet at the beginning, so that there is no
' possibility that there is a similar name on the active sheet
On Error Resume Next
Application.ScreenUpdating = False
Worksheets.Add before:=Sheets(1)
For i = 0 To ListBox1.ListCount - 1
NameIndex = ActiveWorkbook.Names(ListBox1.List(i)).Index
With ActiveWorkbook.Names(NameIndex)
.Visible = True
.Delete ' delete the name
End With
Next i

Application.DisplayAlerts = False
Worksheets(1).Delete 'delete the new sheet
Application.DisplayAlerts = True

Sheets(DisplayedSheet).Select 're-activate the active sheet
Application.ScreenUpdating = True

If ActiveWorkbook.Names.Count = 0 Then
ListBox1.Clear
MsgBox "The active workbook contains no more names.", vbInformation, APPNAME
Unload Me
Exit Sub
Else
' adjust the array
Call GetAllNames
If obAll Then Call obAll_Click
If obWorkbook Then Call obWorkbook_Click
If obSheetLevel Then Call obSheetLevel_Click
If obHidden Then Call obHidden_Click
If obLinked Then Call obLinked_Click
If obBad Then Call obBad_Click
If obBySheet Then Call obBySheet_Click
End If
If NameCount = 0 Then
ReportButton.Enabled = False
Else
MsgBox "One or more names could not be deleted." & vbCrLf & vbCrLf & "Try using Excel's Define Name dialog box to delete the name(s).", vbInformation, APPNAME
End If
ListBox1.SetFocus
On Error GoTo 0
End Sub


Private Sub GotoButton_Click()
' Activates a name, if possible
Dim i As Long
Dim GoToRef As String

On Error Resume Next
For i = 1 To NameCount
If AllNames(i).TheName = ListBox1.Value Then
GoToRef = AllNames(i).RefersTo
GoToRef = Right(GoToRef, Len(GoToRef) - 1)
Exit For
End If
Next i
Application.GoTo Range(GoToRef)
If Err <> 0 Then
MsgBox ListBox1.Value & vbCrLf & ActiveWorkbook.Names(ListBox1.Value) & vbCrLf & vbCrLf & "Cannot go there.", vbInformation, APPNAME
End If
ListBox1.SetFocus
On Error GoTo 0
End Sub

Private Sub UnhideButton_Click()
' unhides a hidden name
Dim i As Long
On Error Resume Next
For i = 1 To NameCount
If AllNames(i).TheName = ListBox1.Value Then
ActiveWorkbook.Names(ListBox1.Value).Visible = True
AllNames(i).Hidden = False
UnhideButton.Enabled = False
Exit For
End If
Next i
If obHidden Then Call obHidden_Click
On Error Resume Next
ListBox1.SetFocus
End Sub

Private Sub ReportButton_Click()
Dim UserSheets As Long
Dim PasteRange As Range
Dim NameBook As Workbook
Dim UserBook As Workbook
Dim r As Long

Set UserBook = ActiveWorkbook
CloseButton.Caption = "Cancel"
UserSheets = Application.SheetsInNewWorkbook
Application.ScreenUpdating = False
Set NameBook = Workbooks.Add
Set Output = NameBook.Sheets(1)
Application.SheetsInNewWorkbook = UserSheets
With Output
.Cells(1, 1) = "Name report for " & UserBook.FullName
.Cells(1, 1).Font.Size = 14
.Cells(1, 1).Font.Bold = True
.Cells(1, 1).Font.Italic = True
.Cells(2, 1) = "Report generated " & Now
.Cells(2, 1).Font.Bold = True
.Cells(2, 1).Font.Italic = True
End With

With Output.Range("A4:H4")
.Font.Bold = True
.Interior.ColorIndex = 36
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
End With

Set PasteRange = Output.Cells(4, 1)
With PasteRange
.Offset(0, 0) = "Name"
.Offset(0, 1) = "Refers to"
.Offset(0, 2) = "On Sheet"
.Offset(0, 3) = "Sheet level"
.Offset(0, 4) = "Defined in"
.Offset(0, 5) = "Hidden"
.Offset(0, 6) = "Linked"
.Offset(0, 7) = "Erroneous"

For r = 1 To NameCount
If r Mod 10 = 0 Then
LabelRefersTo.Caption = "Generating Report: " & r & " of " & NameCount & " names"
DoEvents
End If
.Offset(r, 0) = AllNames(r).TheName
.Offset(r, 1) = "'" & AllNames(r).RefersTo
.Offset(r, 2) = AllNames(r).BySheet
.Offset(r, 3) = AllNames(r).SheetLevel
.Offset(r, 4) = AllNames(r).DefinedIn
.Offset(r, 5) = AllNames(r).Hidden
.Offset(r, 6) = AllNames(r).Linked
.Offset(r, 7) = AllNames(r).Bad
Next r
End With
Output.Range("A4:G500").Columns.AutoFit
If Output.Columns(2).ColumnWidth > 74 Then Output.Columns(2).ColumnWidth = 74
Application.ScreenUpdating = True
Unload Me
End Sub

Private Sub CloseButton_Click()
On Error Resume Next
Output.Parent.Close False
On Error GoTo 0
End
Unload Me
End Sub

Private Sub PUPHelpButton_Click()
Application.Run "pup6.xla!ShowPUPHelp", 660
End Sub
Chúc các bạn thành công
Lê Văn Duyệt
 
levanduyet

levanduyet

Welcome
16/10/04
537
19
18
HCM
my.opera.com
Đây là file Name Lister, mà form đã được "Việt hóa". Các bạn dùng xem sao nha!
Chúc một ngày cuối tuần hạnh phúc.
Chúc các bạn học hỏi được nhiều từ đọan code trên.

Lê Văn Duyệt
levanduyet@gmail.com
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Các bạn nào Down File Add-in NameLister của Levanduyet, khi giải nén xong, các bạn phải chép vào thư mục có PUP6, và chép đè lên File NameLister.pup của PUP6. Khi chép xong, các bạn muốn sử dụng sẽ có thanh Menu PUP6 / Auditing Tools / Name Lister.
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
So sánh tên toàn cục và tên cục bộ

Khi bạn xác định một tên mới bằng hộp Name Box hay Insert / Name /Define, chúng tự động được xem là áp dụng cho toàn tập bảng tính.
Nếu bạn chọn tên từ hộp Name, Excel sẽ kích hoạt đúng trang bảng tính rồi chọn dãy ô mang tên này.
Nếu bạn sử dụng tên cho công thức, tên sẽ tham chiếu đúng ô, dãy đó, cho dù chúng có ở trên một trang bảng tính riêng biệt
Vì những lý do trên, tên này được gọi là tên toàn cục (global name), sử dụng cho toàn bộ các Sheet cho Workbook
Tuy nhiên, có những trường hợp, bạn muốn dùng tên cụ thể trên nhiều Sheet.
TD : Bạn muốn tham chiếu đến hàng Tổng Cộng ở tất cả các Sheet với cùng một cái tên giống nhau :TC, sao cho bạn có thể sao chép công thức ngang qua các Sheet.
Trường hợp này, bạn phải sử dụng tên cục bộ (local name). Để định rõ tên này, bạn chọn Sheet sẽ áp dụng tên này.
Td : Sheet1. Vào Insert / Name / Define, bạn gõ vào hộp tên TC.
Hộp Refers to : Sheet1!$A$150 (A150 là ô chứa giá trị Tổng cộng chẳng hạn).
Bạn cũng làm như vậy cho các Sheet khác, nếu bạn muốn đặt tên là TC TD : Sheet2!$A$150, Sheet3!$A$200...
Bây giờ, bạn trở lại hộp Name, bạn sẽ nhận thấy tên cục bộ dành cho Sheet đã chọn xuất hiện (Sheet làm việc), tên Sheet hiển thị ở bên phải DS hộp tên. Các tên cục bộ dành cho những trang không được chọn sẽ không xuất hiện
Nếu bạn dùng hộp Name ở góc bên trái thanh Formula, bạn định tên cục bộ bằng cách gõ trực tiếp tên Sheet trước tên chọn. Td : Sheet1!TC
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Tên tham chiếu đến một Workbook khác

Nếu bạn muốn xác định một tên để tham chiếu đến một ô, dãy ô trong một Workbook khác, bạn có thể tạo một liên kết được gọi là tham chiếu ngoại (external reference). Khi thực hiện điều này, bạn phải chắc chắn rằng Workbook mà bạn muốn tham chiếu đến phải được mở và đã được lưu.
1/Tại Workbook làm việc mà bạn muốn đặt tên, bạn vào Insert / Name / Define.
2/Gõ vào tên bạn muốn đặt ở hộp Name in Workbook
3/Ở Refers To : Bạn gõ TD : =[Data.xls!]DanhMuc!$B$2:$F200
Trong đó : Data.xls là tên Workbook có chứa vùng dữ liệu mà bạn muốn đặt tên
DanhMuc là tên của Sheet có dữ liệu đó
$B$2:$F$200 : Vùng dữ liệu bạn đặt tên
Lưu ý : Bạn phải đứng tại WorkbooK làm việc để đặt tên. Data.xls là Workbook có chứa dữ liệu để đặt tên
 
B

Bình_OverAC

Over Abnormal / Crazy
14/5/04
846
10
18
42
Nha Trang
Cũng chính điều này mà em cảm thấy rất phiền vì đôi khi dử liệu của em được sử dụng cho rất nhiều wookbook khác nhau. Như cứ mỗi wookbook cứ phải define name lại một lần. Khi dử liệu nguồn của em thay đổi về cấu trúc, chẳng hạn thêm một cột, thì em phải tra lại xem các wookbook nào đã xử dụng nó để mà thay đổi.
Theo chi handung107 thì có cách nào tốt hơn cho việc này không?
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Mỗi Workbook làm việc khác nhau, em có thể đặt những cái tên khác nhau cho cùng một vùng CSDL. Nó cũng tương tự như khi em mở một Workbook mới thì em phải đặt tên lại thôi
Không có cách gì khác hơn được, ngoài việc CSDL của em là dữ liệu động thôi. Khi đó, việc nới thêm hàng hay cột sẽ không là vấn đề đối với một Dynamic Range.
 
W

WhoamI

Cao cấp
OverAC nói:
Khi dử liệu nguồn của em thay đổi về cấu trúc, chẳng hạn thêm một cột, thì em phải tra lại xem các wookbook nào đã xử dụng nó để mà thay đổi
Híc, vẫn có nhiều việc phải làm với Excel rồi :
- Chuyển sang dữ liệu động :
Em cũng đã gặp trường hợp như OverAC khi em tham chiếu = Vlookup(sheet1!$B$2:$E$9;$D2;2;0) nhưng khi em thay đổi cấu trúc dữ liệu nguồn ví dụ như chèn thêm cột vào giữa cột B và C chẳng hạn thì em phải chuyển công thức của em sang Vlookup(sheet1!$B$2:$E$9;$D2;Columns($B$2:$C$9);0) có thể được gọi là một VD về dữ liệu động không chị?
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Global Range và Local Name

Tên cục bộ (Local Name), được định nghĩa cho một vùng của Sheet đó. Nếu ta muốn có cùng một tên (Td : TC) cho tất cả các Sheet trong cùng một Workbook tại Cell A100 chẳng hạn, ta có thể thực hiện như sau :
-Vào Insert / Name / Define, tại hộp Name in Workbook ta gõ : TC
- Hộp Refers To : =OFFSET(!$A$100,,,,)
(Áp dụng cho vùng sẽ là : Td :=OFFSET(!$A$1:$A$100,,,,))

Như vậy, tên TC xem như tên cục bộ, vì khi bạn đứng tại Sheet nào, bạn gõ =TC tại Cell bất kỳ, Cell này sẽ có giá trị của Cell A100 của Sheet đó
Ngược lại, Cell A100 với tên TC lại được gọi là Global Range, vì có cùng một địa chỉ tại tất cả các Sheet trong cùng một Workbook

Đặt tên như vậy, dù là tên cục bộ, nhưng nó không thể hiện trong hộp Insert/Name/Define như những tên cục bộ đặt theo cách bình thường (Gõ Sheet!Ten) , ta nhận biết khi gõ vào hộp Name Box ở phía bên trái thanh Formula tên của vùng đó, vùng sẽ được chọn
 
H

handung107

Cao cấp
28/8/04
576
15
0
VN
www.giaiphapexcel.com
Thứ tự tìm kiếm các tên trong Excel

Giả sử bạn có một Workbook và có 2 Sheet, Sheet 1 có vùng mang tên cục bộ là Sheet1!TriGia, Sheet 2 có vùng mang tên tổng quát là TriGia. Khi Sheet 1 hoạt động, bạn muốn thiết lập công thức : =SUM(Book1!TriGia) để tính tổng các giá trị trong vùng mang tên TriGia ở Sheet 2.
Nhưng Excel sẽ ngay lập tức biến công thức này thành =SUM(Sheet1!TriGia), đó chính là thứ tự tìm kiếm các tên miền giống nhau của Excel.
Tại Sheet 1, Excel gặp tên TriGia trong công thức SUM, nó trả về tên cục bộ đến Sheet 1.
Bây giờ, tại Sheet 2, bạn nhập =SUM(Sheet2!TriGia) thay vì =SUM(Book1!TriGia), do Sheet 2 không có tên cục bộ, nên Excel đi tìm tiếp tên tổng quát. Và vì chỉ có một tên tổng quát là TriGia, nên Excel sẽ thay đổi Sheet2!TriGia thành Book1!TriGia.
Ngược lại, tại Sheet 3 trong Book 1, không chứa tên cục bộ, hoặc tên tổng quát TriGia, nên trên Sheet 3, bạn có thể nhập : =SUM(Book1!TriGia), và Excel sẽ không sửa đổi những gì bạn nhập.
Trong cả 2 trường hợp, Excel sẽ trả về tổng của tên tổng quát TriGia trên Sheet 2
 

Xem nhiều

Webketoan Zalo OA