Especificar formato desde macro

04/04/2007 - 04:46 por JLMorales | Informe spam
Hola grupo:
Tengo el siguiente código:
Sub Reporte()
Application.ScreenUpdating = False
Dim wksCli As Worksheet, wksFic As Worksheet
Dim rngO As Range, rngArea As Range
Dim lngFilas As Long, n As Long

ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Reporte"
Range("A1:D1").Font.Bold = True
Range("A1").Value = "Fecha"
Range("B1").Value = "Inicio"
Range("C1").Value = "Fin"
Range("D1").Value = "Folio"
j = ActiveCell.Row + 1

Worksheets("Hoja de Servicio").Activate

Set wksCli = Worksheets("Hoja de Servicio")
Set wksFic = Worksheets("Reporte")
Set rngO = Selection

If ActiveSheet.Name <> "Hoja de Servicio" Then Exit Sub

For Each rngArea In rngO.Areas
lngFilas = lngFilas + rngArea.Rows.Count
Next rngArea

MsgBox ("Se generará reporte de " & lngFilas & " registros.")

For Each rngArea In rngO.Areas
For n = 1 To rngArea.Rows.Count
With wksFic

.Cells(j, 1).Value =
Format(wksCli.Cells(rngArea.Rows(n).Row, 58), "mm/dd/yyyy")
.Cells(j, 2).Value =
Format(wksCli.Cells(rngArea.Rows(n).Row, 62), "hh:mm:ss")
.Cells(j, 3).Value =
Format(wksCli.Cells(rngArea.Rows(n).Row, 89), "hh:mm:ss")
.Cells(j, 4).Value = wksCli.Cells(rngArea.Rows(n).Row, 59)
j = j + 1
.Cells(j, 1).Value = "Reporte para: " &
wksCli.Cells(rngArea.Rows(n).Row, 60)
j = j + 1
.Cells(j, 1).Value = "Justificación: " &
wksCli.Cells(rngArea.Rows(n).Row, 63)
j = j + 1
.Cells(j, 1).Value = "Solicita: " &
wksCli.Cells(rngArea.Rows(n).Row, 66) & "; " & _
wksCli.Cells(rngArea.Rows(n).Row, 68)
j = j + 1
.Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
j = j + 1
End With
Next n
Next rngArea

Set rngArea = Nothing
Set rngO = Nothing
Set wksFic = Nothing
Set wksCli = Nothing
Application.ScreenUpdating = False
'
End Sub

Cuando paso los valores de wksCli a wksFic, necesito poner los cuatro
primeros valores en negritas. He estado intentando con las propiedades de
range() y cells() pero no me funciona.

La siguiente línea de código: .Cells(j, 1).Value =
wksCli.Cells(rngArea.Rows(n).Row, 87); el valor del origen
wksCli.Cells(rngArea.Rows(n).Row, 87) contiene varias lineas en la celda, y
necesito que cuando aplique el reporte me deje el destino en formato general.
Ahí no tengo ni la mas remota idea de cómo hacerlo.

Hasta ahora, genero el reporte y el formato lo hago manual. ¿me puede ayudar
con esto?

Saludos

Preguntas similare

Leer las respuestas

#1 Héctor Miguel
04/04/2007 - 08:32 | Informe spam
hola, JLMorales !

__ 1 __
Tengo el siguiente codigo: [...]
Cuando paso los valores de wksCli a wksFic, necesito poner los cuatro primeros valores en negritas.
He estado intentando con las propiedades de range() y cells() pero no me funciona.


__ 2 __
La... linea: .Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
el valor del origen wksCli.Cells(rngArea.Rows(n).Row, 87)
contiene varias lineas en la celda, y necesito que cuando aplique el reporte me deje el destino en formato general.
Ahi no tengo ni la mas remota idea de como hacerlo.
Hasta ahora, genero el reporte y el formato lo hago manual...



1) ya 'manejaste' el establecer la fuente en negritas aplicando la propiedad a un objeto Range(...)
-> Range("A1:D1").Font.Bold = True
-> si te ha 'confundido' el cambio de Range a 'Cells'... prueba combinando Range(Cells(... +/- como sigue:

With wksFic
.Cells(j, 1).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 58), "mm/dd/yyyy")
.Cells(j, 2).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 62), "hh:mm:ss")
.Cells(j, 3).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 89), "hh:mm:ss")
.Cells(j, 4).Value = wksCli.Cells(rngArea.Rows(n).Row, 59)
.Range(.Cells(j, 1), .Cells(j, 4)).Font.Bold = True ' <= esta linea es 'nueva' :)) '

2) para el caso de aplicar el formato 'numerico' general, luego de pasarle el valor a la celda, aplica 'el formato' +/- como sigue:

.Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
.Cells(j, 1).NumberFormat = "general" ' <= esta linea es 'nueva' :)) '

si cualquier duda [o informacion adicional]... comentas ?
saludos,
hector.

p.d. [por cierto]... el codigo tiene toda la 'pinta/firma/forma/...' de Fernando Arroyo :))

___ el codigo expuesto __
Sub Reporte()
Application.ScreenUpdating = False
Dim wksCli As Worksheet, wksFic As Worksheet, rngO As Range, rngArea As Range, lngFilas As Long, n As Long
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Reporte"
Range("A1:D1").Font.Bold = True
Range("A1").Value = "Fecha"
Range("B1").Value = "Inicio"
Range("C1").Value = "Fin"
Range("D1").Value = "Folio"
j = ActiveCell.Row + 1
Worksheets("Hoja de Servicio").Activate
Set wksCli = Worksheets("Hoja de Servicio")
Set wksFic = Worksheets("Reporte")
Set rngO = Selection
If ActiveSheet.Name <> "Hoja de Servicio" Then Exit Sub
For Each rngArea In rngO.Areas
lngFilas = lngFilas + rngArea.Rows.Count
Next rngArea
MsgBox ("Se generara reporte de " & lngFilas & " registros.")
For Each rngArea In rngO.Areas
For n = 1 To rngArea.Rows.Count
With wksFic
.Cells(j, 1).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 58), "mm/dd/yyyy")
.Cells(j, 2).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 62), "hh:mm:ss")
.Cells(j, 3).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 89), "hh:mm:ss")
.Cells(j, 4).Value = wksCli.Cells(rngArea.Rows(n).Row, 59)
j = j + 1
.Cells(j, 1).Value = "Reporte para: " & wksCli.Cells(rngArea.Rows(n).Row, 60)
j = j + 1
.Cells(j, 1).Value = "Justificacion: " & wksCli.Cells(rngArea.Rows(n).Row, 63)
j = j + 1
.Cells(j, 1).Value = "Solicita: " & wksCli.Cells(rngArea.Rows(n).Row, 66) & "; " & _
wksCli.Cells(rngArea.Rows(n).Row, 68)
j = j + 1
.Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
j = j + 1
End With
Next n
Next rngArea
Set rngArea = Nothing
Set rngO = Nothing
Set wksFic = Nothing
Set wksCli = Nothing
Application.ScreenUpdating = False
End Sub
Respuesta Responder a este mensaje
#2 JLMorales
04/04/2007 - 22:28 | Informe spam
Hola Miguel:
Gracias por la orientación. Probaré tu propuesta en el código.
Por cierto, claro! el codigo tiene toda la 'pinta/firma/forma/...' de
Fernando Arroyo . Este código fue compartido en algun momento por él, y
agradesco nuevamente su aporte, como a tí hoy te reitero mi respeto y
agradecimiento por orientar a tantas personas que como yo, que nos iniciamos
en el mundo de la programación visual.

Saludos
"Héctor Miguel" wrote:

hola, JLMorales !

__ 1 __
> Tengo el siguiente codigo: [...]
> Cuando paso los valores de wksCli a wksFic, necesito poner los cuatro primeros valores en negritas.
> He estado intentando con las propiedades de range() y cells() pero no me funciona.
__ 2 __
> La... linea: .Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
> el valor del origen wksCli.Cells(rngArea.Rows(n).Row, 87)
> contiene varias lineas en la celda, y necesito que cuando aplique el reporte me deje el destino en formato general.
> Ahi no tengo ni la mas remota idea de como hacerlo.
> Hasta ahora, genero el reporte y el formato lo hago manual...

1) ya 'manejaste' el establecer la fuente en negritas aplicando la propiedad a un objeto Range(...)
-> Range("A1:D1").Font.Bold = True
-> si te ha 'confundido' el cambio de Range a 'Cells'... prueba combinando Range(Cells(... +/- como sigue:

With wksFic
.Cells(j, 1).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 58), "mm/dd/yyyy")
.Cells(j, 2).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 62), "hh:mm:ss")
.Cells(j, 3).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 89), "hh:mm:ss")
.Cells(j, 4).Value = wksCli.Cells(rngArea.Rows(n).Row, 59)
.Range(.Cells(j, 1), .Cells(j, 4)).Font.Bold = True ' <= esta linea es 'nueva' :)) '

2) para el caso de aplicar el formato 'numerico' general, luego de pasarle el valor a la celda, aplica 'el formato' +/- como sigue:

.Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
.Cells(j, 1).NumberFormat = "general" ' <= esta linea es 'nueva' :)) '

si cualquier duda [o informacion adicional]... comentas ?
saludos,
hector.

p.d. [por cierto]... el codigo tiene toda la 'pinta/firma/forma/...' de Fernando Arroyo :))

___ el codigo expuesto __
Sub Reporte()
Application.ScreenUpdating = False
Dim wksCli As Worksheet, wksFic As Worksheet, rngO As Range, rngArea As Range, lngFilas As Long, n As Long
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Reporte"
Range("A1:D1").Font.Bold = True
Range("A1").Value = "Fecha"
Range("B1").Value = "Inicio"
Range("C1").Value = "Fin"
Range("D1").Value = "Folio"
j = ActiveCell.Row + 1
Worksheets("Hoja de Servicio").Activate
Set wksCli = Worksheets("Hoja de Servicio")
Set wksFic = Worksheets("Reporte")
Set rngO = Selection
If ActiveSheet.Name <> "Hoja de Servicio" Then Exit Sub
For Each rngArea In rngO.Areas
lngFilas = lngFilas + rngArea.Rows.Count
Next rngArea
MsgBox ("Se generara reporte de " & lngFilas & " registros.")
For Each rngArea In rngO.Areas
For n = 1 To rngArea.Rows.Count
With wksFic
.Cells(j, 1).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 58), "mm/dd/yyyy")
.Cells(j, 2).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 62), "hh:mm:ss")
.Cells(j, 3).Value = Format(wksCli.Cells(rngArea.Rows(n).Row, 89), "hh:mm:ss")
.Cells(j, 4).Value = wksCli.Cells(rngArea.Rows(n).Row, 59)
j = j + 1
.Cells(j, 1).Value = "Reporte para: " & wksCli.Cells(rngArea.Rows(n).Row, 60)
j = j + 1
.Cells(j, 1).Value = "Justificacion: " & wksCli.Cells(rngArea.Rows(n).Row, 63)
j = j + 1
.Cells(j, 1).Value = "Solicita: " & wksCli.Cells(rngArea.Rows(n).Row, 66) & "; " & _
wksCli.Cells(rngArea.Rows(n).Row, 68)
j = j + 1
.Cells(j, 1).Value = wksCli.Cells(rngArea.Rows(n).Row, 87)
j = j + 1
End With
Next n
Next rngArea
Set rngArea = Nothing
Set rngO = Nothing
Set wksFic = Nothing
Set wksCli = Nothing
Application.ScreenUpdating = False
End Sub



email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida