-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.bas
More file actions
59 lines (33 loc) · 2 KB
/
Copy pathFunctions.bas
File metadata and controls
59 lines (33 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Attribute VB_Name = "Functions"
Option Explicit
Option Base 1
Function fUltimaLinhaPlan(PlanRef As String) As Long
fUltimaLinhaPlan = ThisWorkbook.Worksheets(PlanRef).Range("A1048576").End(xlUp).Row
End Function
Public Function fUltimaColunaPlan(PlanRef As String) As Long
fUltimaColunaPlan = ThisWorkbook.Worksheets(PlanRef).Range("XFD1").End(xlToLeft).Column
End Function
Public Function fLinhaAtualPlan(PlanRef As String) As Long
fLinhaAtualPlan = ThisWorkbook.Worksheets(PlanRef).Range(ActiveCell.Address).Rows("1:1").Row
End Function
Public Function fColunaAtualPlan(PlanRef As String) As Long
fColunaAtualPlan = ThisWorkbook.Worksheets(PlanRef).Range(ActiveCell.Address).Columns("A:A").Column
End Function
Function fUltimaLinhaIntervalo(PlanRef As String, Coluna As String) As Long
fUltimaLinhaIntervalo = ThisWorkbook.Worksheets(PlanRef).Range(Coluna & "1048576").End(xlUp).Row
End Function
Sub AtualizaNomes(Nome As String, Planilha As String, CellInicial As String, UltimaColuna As String)
'Não é função propriamente dita, pois não retorna dados, mas está aqui porque é como se fosse uma função
Dim UltimaLinhaPlanRef As Long
UltimaLinhaPlanRef = fUltimaLinhaPlan(Planilha)
ThisWorkbook.Names(Nome).Delete
ThisWorkbook.Names.Add Name:=Nome, RefersTo:=Range(Planilha & "!" & CellInicial & ":" & UltimaColuna & UltimaLinhaPlanRef)
End Sub
Sub AtualizaNomesIntervalo(Nome As String, Planilha As String, CellInicial As String, Coluna As String, fColuna As String)
'Não é função propriamente dita, pois não retorna dados, mas está aqui porque é como se fosse uma função
Dim UltimaLinhaIntervalo As Long
'Caso o intervalo não tenha todas as linhas preenchidas, fColuna deve ser uma coluna sem células vazias
UltimaLinhaIntervalo = fUltimaLinhaIntervalo(Planilha, fColuna)
ThisWorkbook.Names(Nome).Delete
ThisWorkbook.Names.Add Name:=Nome, RefersTo:=Range(Planilha & "!" & CellInicial & ":" & Coluna & UltimaLinhaIntervalo)
End Sub