Excel - Como incluir en una macro existente una nueva condicion

 
Vista:

Como incluir en una macro existente una nueva condicion

Publicado por heidi (4 intervenciones) el 19/05/2016 19:02:15
Buenas tardes,

No tengo mucha experiencia con macros pero tengo una existente y debo modificarla, de tal modo que:

Cuando se ejecute, lo último que haga es sombrear la o las celdas en rojo que contengan una palabra en concreto y en el caso de que no, se finaliza con normalidad. Esto es posible?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Andres Leonardo
Val: 3.136
Plata
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Como incluir en una macro existente una nueva condicion

Publicado por Andres Leonardo (1583 intervenciones) el 19/05/2016 20:48:55
Hola ... pues mira lo que pasa es que me parece que deberias hacer otra macro que recorra un rango y verifique las celdas con ese contenido y marcarlas con ese color.....
... podrias poner tu codigo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Como incluir en una macro existente una nueva condicion

Publicado por heidi (4 intervenciones) el 20/05/2016 16:46:28
Hola buenas...ya he hecho la macro y funciona pero por ahora lo que hago es que con el boton de la primera macro se ejecuta solo esa, luego tengo que ejecutar la segunda macro manualmente. Podria aprovechar el boton de la primera para que ejecute todo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Andres Leonardo
Val: 3.136
Plata
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Como incluir en una macro existente una nueva condicion

Publicado por Andres Leonardo (1583 intervenciones) el 20/05/2016 18:19:33
llámala dentro de la macro

sub macro1()
'todo lo que sea
todo la macro

'llamara la otra macro

macro2()

end sub
Saludos
Andres
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Como incluir en una macro existente una nueva condicion

Publicado por heidi (4 intervenciones) el 24/05/2016 10:02:22
Buenas Andres,

He estado haciendo pruebas y no me funciona...algo debo estar colocando mal ya que cuando grabo y quiero ejecutar con el boton me sale el siguiente error:

Error de compilacion
No se ha definido sub o function

y me sale en amarillo: Private Sub CommandButton1_Click()
modulo1.el nombre de la primera macro ()
end sub

Con esta informacion me puedes ayudar o necesitas mas datos?

gracias!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Andres Leonardo
Val: 3.136
Plata
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Como incluir en una macro existente una nueva condicion

Publicado por Andres Leonardo (1583 intervenciones) el 24/05/2016 15:52:46
no pongas modulo solo

1
2
3
Private Sub CommandButton1_Click()
nombreDeLaPrimeraMacro()
end sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Como incluir en una macro existente una nueva condicion

Publicado por heidi (4 intervenciones) el 24/05/2016 17:06:47
Hola Andres, no logro conseguir que funcionen las dos macros, utilizando el botón de la primera. Te pongo las dos macros para que lo veas mejor tu y si puedes hacer que funcionen te lo agradecería muchisimo....

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
Sub documento_unico()
'
' documento_unico Macro
' 
'
 
    archivo_lt10 = InputBox("Introduce el archivo lt10 de traspasos a ...TRANSIT")
 
    archivoconruta = "C:\temp\Macro Operadores\" & archivo_lt10 & ".xls"
 
    'Workbooks.OpenText Filename:="C:\temp\Macro Operadores\" & archivo_lt10 & ".xls", Origin:= _
        932, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1 _
        ), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1)), _
        TrailingMinusNumbers:=True
 
        Workbooks.OpenText Filename:="C:\temp\Macro Operadores\" & archivo_lt10 & ".xls", _
        Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=True, OtherChar:="|", FieldInfo:= _
        Array(1, 1)
 
 
    Rows("1:4").Select
    Selection.Delete Shift:=xlUp
 
    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
 
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
 
    Range("H:H,M:M,F:F").Select
    Range("M1").Activate
    Selection.NumberFormat = "0"
 
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Número de EM"
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "CR/P1"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "Material"
    Range("D1").Select
    ActiveCell.FormulaR1C1 = "Proveedor"
    Range("E1").Select
    ActiveCell.FormulaR1C1 = "Denominación"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Stock"
    Range("G1").Select
    ActiveCell.FormulaR1C1 = "UN"
    Range("H1").Select
    ActiveCell.FormulaR1C1 = "UA"
    Range("I1").Select
    ActiveCell.FormulaR1C1 = "Alm"
    Range("J1").Select
    ActiveCell.FormulaR1C1 = "Ubicación"
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "Ctro"
    Range("L1").Select
    ActiveCell.FormulaR1C1 = "Fecha Trasp"
    Range("M1").Select
    ActiveCell.FormulaR1C1 = "Lote insp"
    Range("N1").Select
    ActiveCell.FormulaR1C1 = "Hora"
 
    Workbooks.Open Filename:="C:\temp\Macro Operadores\Materiales_Proveedor.xls"
 
     Workbooks(archivo_lt10 & ".xls").Activate
 
        Range("D2").Select
        ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-1],'[Materiales_Proveedor.xls]Hoja1'!C1:C4,4,FALSE)"
 
 
        Range("E2").Select
        ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-2],'[Materiales_Proveedor.xls]Hoja1'!C1:C4,2,FALSE)"
 
    Fin = 0
    For cont = 3 To 65536
 
        If Cells(cont, 1) <> "" Then
            Range("D2:E2").Select
            Selection.Copy
            Range("D" & cont & ":E" & cont).Select
            ActiveSheet.Paste
            Fin = 0
        End If
 
        If Cells(cont, 1) = "" Then
            Fin = Fin + 1
                If Fin = 2 Then
                Exit For
 
                End If
            End If
 
    Next
 
 
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1:N1").Select
    With Selection.Interior
        .ColorIndex = 1
        .Pattern = xlSolid
    End With
    Selection.Font.ColorIndex = 2
 
 
    Columns("A:N").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
 
 
    Rows("1:1").Select
    Range("C1").Activate
    Application.CutCopyMode = False
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
 
    Columns("D:D").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
 
    Columns("A:A").Select
    Selection.EntireColumn.Hidden = True
 
    Cells.Select
    'Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("D2") _
        , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False _
        , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
        xlSortNormal
 
    Columns("A:N").Select
    Range("N1").Activate
    Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("D2") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom
 
    Workbooks.Open Filename:="C:\temp\Macro Operadores\Piezas ubicacion fija.xls"
 
    Workbooks(archivo_lt10 & ".xls").Activate
 
    Columns("I:I").Select
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
 
 
 
    Fin = 0
    For cont = 2 To 65536
 
        If Cells(cont, 1) <> "" Then
 
            Range("J" & cont).Select
            ActiveCell.FormulaR1C1 = _
            "=VLOOKUP(RC[-6],'[Piezas ubicacion fija.xls]Hoja1'!C1:C4,4,FALSE)"
 
            Range("J" & cont).Select
            Selection.Copy
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
 
 
            Range("J" & cont).Select
            'Selection.Replace What:="#N/A", Replacement:="0", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            ActiveCell.Replace What:="#N/A", Replacement:="0", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False
 
            'Cells.Find(What:="#N/A", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False).Activate
 
 
            'Range("I" & cont).Select
            'ActiveCell.FormulaR1C1 = "=IF(RC[1]=0,RC[3],RC[1])"
 
            If Cells(cont, 10) = 0 Then
 
                  Cells(cont, 9) = Cells(cont, 12)
 
                  Else
 
                    Cells(cont, 9) = Cells(cont, 10)
                    Rows(cont).Select
                    With Selection.Interior
                    .ColorIndex = 15
                    .Pattern = xlSolid
                    End With
 
            End If
 
            Range("I" & cont).Select
            Selection.Copy
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
 
            Fin = 0
        End If
 
        If Cells(cont, 1) = "" Then
            Fin = Fin + 1
                If Fin = 2 Then
                Exit For
 
                End If
            End If
 
    Next
 
    Range("J:J,L:L").Select
    Range("L1").Activate
    Selection.Delete Shift:=xlToLeft
 
    Range("I1").Select
    ActiveCell.FormulaR1C1 = "Ubicación"
 
 
    Rows("1:1").RowHeight = 27
    Columns("B:B").ColumnWidth = 24
    Columns("C:C").ColumnWidth = 4
    Columns("D:D").ColumnWidth = 11
    Columns("E:E").ColumnWidth = 22
    Columns("G:G").ColumnWidth = 3
    Columns("H:H").ColumnWidth = 12
    Columns("I:I").ColumnWidth = 13
    Columns("L:L").ColumnWidth = 9
 
    With ActiveSheet.PageSetup
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(0.5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        '.PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        '.PrintErrors = xlPrintErrorsDisplayed
 
    End With
 
End Sub
 
 
 
Sub rojo()
'
' ROJO Macro
'
 
'
    Columns("I:I").Select
    With Application.ReplaceFormat.Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Selection.Replace What:="XXXX", Replacement:="XXXX", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=True
    ActiveWorkbook.Worksheets("doc").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("doc").Sort.SortFields.Add Key:=Range("I2:I84"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("doc").Sort
        .SetRange Range("I1:I84")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("K5").Select
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar