ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Create a procedure or function (https://www.excelbanter.com/excel-worksheet-functions/210876-create-procedure-function.html)

Alexandra Lopes

Create a procedure or function
 
Hello everyone!

I'm now using Excel 2007.

I have a file with some sheets. In one of the sheets I have the
following code:

Sub CSO()
' CSO Macro
' ordenar colaboradores por ranking
'
' Keyboard Shortcut: Ctrl+o
'

ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("R9:R40"), _
SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("B9:AA40")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

bons = ActiveWorkbook.ActiveSheet.Range("AL12")
medios = ActiveWorkbook.ActiveSheet.Range("AL10")
maus = ActiveWorkbook.ActiveSheet.Range("AL9")

celinicio = 9
celula = "AG" + CStr(celinicio)
celulanome = "B" + CStr(celinicio)
'contador = bons
Total = bons + medios + maus

For i = 1 To Total
If bons 0 Then
celula = "AE" + CStr(celinicio)
ActiveWorkbook.ActiveSheet.Range(celula) =
ActiveWorkbook.ActiveSheet.Range(celulanome)
bons = bons - 1
ElseIf medios 0 Then
celula = "AD" + CStr(celinicio)
ActiveWorkbook.ActiveSheet.Range(celula) =
ActiveWorkbook.ActiveSheet.Range(celulanome)
medios = medios - 1
ElseIf maus 0 Then
celula = "AC" + CStr(celinicio)
ActiveWorkbook.ActiveSheet.Range(celula) =
ActiveWorkbook.ActiveSheet.Range(celulanome)
maus = maus - 1
End If
celinicio = celinicio + 1
celulanome = "B" + CStr(celinicio)

Next i
End Sub



I intend to create a procedure or function (to go to search to help) and
later invoking in each one of sheets this procedure, of form to apply
this code in some sheets.

Please help and thanks in advance!


All times are GMT +1. The time now is 09:28 PM.

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