Macro for autofilter

Santino_X

New Member
Joined
May 1, 2011
Messages
15
Good afternoon, Im trying to record a macro using data->filter->custom filter
using ends with c/?? or ends with c??
to represent 2 individual characters.
I´m using excel 2007 and i have read that i can´t record macros. Can anyone give me the code for the filter i´m trying to do?
Thanks:)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the Board!

I don't know where you read that, but you absolutely can record macros in Excel 2007.

Give it a try, and post back what you get so someone can fix up it for you.
 
Upvote 0
Thanks.
I have just foud how to modify the macro i´ve been recording. I have experience programming but i don´t know if the form it is written is correct.
I´m using the % symbol as the remainder of a division.
I have this code:

Sub Macroprota()
Application.ScreenUpdate=False
Application.Calculation=xlCalculationManual

Dim ctotal As Integer, cposible As Integer,contador As Integer
, paquete As String

For contador=1 to 9551


Range(contador,6).Select
ActiveSheet.Range(contador, 6).AutoFilter Field:=1, Criteria1:="=*c/??", _Operator:=xlOr, Criteria2:="=*c??"
'Here i need to give the value of this

If paquete==c/15 Then
ctotal=Range(contador,15)*2-Range(contador,12)
cposible=ctotal%15
If cposible>8 Then
ctotal=ctotal+cposible
Else
ctotal=ct0tal-cposible
EndIf
Next contador
Application.ScreenUpdate=True
Application.Calculation=xlCalculationAutomatic
End Sub


And the thing i need now is to pass the last digits of the String value to the variable called paquete. Thanks
 
Upvote 0
Please see comments in the code for questions.
Code:
Sub Macroprota()
 
    Application.ScreenUpdate = False
    Application.Calculation = xlCalculationManual
 
    Dim contador    As Integer, _
        cposible    As Integer, _
        ctotal      As Integer, _
        paquete     As String
 
    For contador = 1 To 9551        '// ¿porqué 9551?
 
        Range(contador, 6).Select
 
        ActiveSheet.Cells(contador, 6).AutoFilter Field:=1, _
                                                  Criteria1:="=*c/??", _
                                                  Operator:=xlOr, _
                                                  Criteria2:="=*c??"
 
        '// favor explice qué es la condición que desea evaluar
        '// y de donde saca paquete su valor porque no veo
        '// nada que da un valor a paquete.
        If paquete==c/15 Then
            ctotal = Range(contador, 15) * 2 - Range(contador, 12)
            '// favor explica que intenta aquí
            cposible=ctotal%15
            If cposible > 8 Then
                ctotal = ctotal + cposible
            Else
                ctotal = ct0tal - cposible
            End If
        End If
    Next contador
 
    Application.ScreenUpdate = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
El 9551 sale de la cantidad de Strings que tengo en mi base de datos.
Luego de esas Strings, quiero tomar los ultimos digitos para y evaluar si contiene c/15 u otro valor y copiarlo a la variable paquete.
Luego tengo problemas con el comparador ==, no se como sea en excel al igual que con el simbolo % para sacar el residuo de las divisiones.
Gracias
 
Upvote 0
Santino,

I asked our resident Spanish expert (Senor Truby) to help me with your post, and have since moved it to the other languages forum.

Sorry I couldn't help you earlier, but that's why I asked Greg.

Buenos noches.
 
Upvote 0
Digamos que despues de resolver el residuo manualmente tengo este codigo:

Sub total()

Application.ScreenUpdate = False
Application.Calculation = xlManual
Dim ctotal As Integer, cposible As Integer, contador As Integer, paquete As String

For contador = 2 To 9551
paquete = Range(contador, 6).Value

/*Aqui debe de ir una formula para seleccionar los ultimos caracteres del String y pasarle el valor
a paquete*/

If Range(contador, 6).Value = c / 3 Then
ctotal = Range(contador, 15).Value * 2 - Range(contador, 12).Value
cposible = ctotal / 3
cposible = ctotal - (cposible * 3)
If cposible < 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Range(contador, 22).Value = ctotal
End If
Next contador

Application.ScreenUpdate = True
Application.Calculation = xlAutomatic
End Sub
 
Last edited:
Upvote 0
Hola Santino,

Para extraer los primeros 3 caracteres de un dato del inicio o del final, podés usar las funciones Left or Right
(estas son dentro del ambiente VBA) porque también las hay dentro de las funciones de Hoja de Excel. Ejemplo:

Code:
[COLOR=Green]'Extraer primeros 3 caracteres a la izquierda de celda(1,1)=A1[/COLOR]
Primeros_Caracteres = Left(Cells(1, 1), 3)

[COLOR=Green]'Extraer últimos 3 caracteres a la derecha de celda(1,1)=A1[/COLOR]
Ultimos_Caracteres = Right(Cells(1, 1), 3)
Para la parte del uso de expresión regular o comodines en el Autofiltro, abajo hay algunos ejemplos:

1-) Filtrar para celdas que contienen c/ seguido de cualquiera cadena de caracteres *
Code:
[COLOR=Green]'Esto al inicio[/COLOR] [B][COLOR=Blue]"=[/COLOR][/B] [COLOR=Green]y esto[/COLOR] [COLOR=Green]al final [/COLOR][B][COLOR=Blue]*"[/COLOR][/B] [COLOR=Green], lo requiere Excel en su sintaxis.[/COLOR]
ActiveSheet.Range("$J$1:$J$23").AutoFilter Field:=1, _ 
Criteria1:=[B][COLOR=Blue]"=[/COLOR][COLOR=Red]*c/*[/COLOR][COLOR=Blue]*"[/COLOR][/B], Operator:=xlAnd
2-) Filtrar para celdas que contienen c/ seguido de un caracter cualquiera ?
Code:
ActiveSheet.Range("$J$1:$J$23").AutoFilter Field:=1, _ 
Criteria1:="=*[COLOR=Red][B]c/?[/B][/COLOR]*", Operator:=xlAnd
3-) Filtrar para celdas que contienen c/ seguido de un caracter cualquiera ? y luego de un 5
Code:
ActiveSheet.Range("$J$1:$J$23").AutoFilter Field:=1, _ 
Criteria1:="=*[B][COLOR=Red]c/?5[/COLOR][/B]*", Operator:=xlAnd
En la parte de "If paquete==c/15 Then" solo es necesario un signo igual asi:
Code:
[COLOR=Green]'En este caso [COLOR=Navy][B]c[/B][/COLOR] se tomaría como variable que está siendo dividida por 15[/COLOR]
If paquete=c/15 Then

Si c/15 es una cadena de texto, entonces debería ir entre comillas dobles así:
Code:
If paquete="c/15" Then
Espero ayude.

Saludos cordiales
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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