PDA

View Full Version : [SOLVED:] Generate an table Index



tomzko
12-29-2015, 08:03 PM
Hi, i need an urgent help plz! im having problems (cause im an ignorant in VBA and macros) modifiying this macro:
15066
What i need to do is change the table where the macro gets the information, those are [A3:A5] and [B3:B5].
the cells that i really want to get the information are: [A4:A6] and [B4:B6].
i know it sound silly but ive been like 2 hours trying to find the solution but i cant because i dont know programming :´(
please help me :) its very important

SamT
12-29-2015, 09:25 PM
This one?
Public Sub CrearEncabezamiento()
Dim Columna As Integer
Application.ScreenUpdating = False
FormatearEncabezado
Columna = 11
For x = 3 To Hoja1.Range("A" & Rows.Count).End(xlUp).Row
For y = 1 To Hoja1.Range("A" & x)
If Columna > 1 Then Hoja1.Range("K1:N3").Copy Hoja1.Cells(1, Columna)
Hoja1.Cells(1, Columna) = "Camión " & y & Hoja1.Range("B" & x)
Columna = Columna + 4
Next
Next
Hoja1.Select
End Sub

See if I got this right
Public Sub CrearEncabezamiento()
'For help see: http://www.vbaexpress.com/forum/showthread.php?54672-Generate-an-table-Index

Dim rngCantidad As Range
Dim Columna As Long
Const finaCantidadRow As Long = 6
'Alternative: to use all Cantidadas (more than A4:A6)
'Dim finaCantidadRow as long
' finaCantidad = Sheets("Hoja1").Cells(Rows.Count, 1).End(xlUp).Row

Application.ScreenUpdating = False
FormatearEncabezado

With Sheets("Hoja1")
Set rngCantidad = .Range("A4") 'First Cantidad

'From first Camion Column to last Camion Column stepping 4 columns at a time
For Columna = 11 To .Cells(1, Columns.Count).End(xlToLeft).Column Step 4
.Cells(1, Columna) = "Camión " & rngCantidad & rngCantidad.Offset(0, 1)

'Move cantidad Range down one Row
Set rngCantidad = rngCantidad.Offset(1)
If rngCantidad.Row = finaCantidadRow Then Exit For
Next
End With

Application.ScreenUpdating = True
End Sub

tomzko
12-30-2015, 02:16 PM
Thank for the help! :)