S
Sean
I have the following code below which posts various values that are
within sheet "Report" to a sheet called "Database"
How would I cnage the code below to post the same details except to
different worksheets depending on the value in Report K6?
For example, if Report K6 = London, then post the values (as below) to
a sheet called "Database London". If Report K6 = Paris, then post the
values (as below) to a sheet called "Database Paris".
Thanks
Sub Database_Post()
Dim r As Long, c As Long, rng As Range
Dim MyValues(9, 5), MyHeaders(3), MyColumns
Application.ScreenUpdating = False
Set rng = Sheets("Database").Cells(65536, "E").End(xlUp).Offset(1,
0)
MyColumns = Array("A", "C", "H", "K", "M")
For r = 0 To 8
For c = 0 To UBound(MyColumns)
MyValues(r, c) = _
Sheets("Report").Cells(18 + 5 * r, MyColumns(c)).Value
Next c
Next r
With Sheets("Report")
MyHeaders(0) = .Range("E6").Value
MyHeaders(1) = .Range("K6").Value
MyHeaders(2) = .Range("E9").Value
MyHeaders(3) = .Range("E12").Value
End With
rng.Resize(10, 5).Value = MyValues
On Error Resume Next
rng.Offset(0, -4).Resize(rng.Parent.Cells(65536, "E") _
.End(xlUp).Row - rng.Row + 1, 4) = MyHeaders
Sheets("Database").Select
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Range("A1").Select
Sheets("Report").Select
Range("A1").Select
End Sub
within sheet "Report" to a sheet called "Database"
How would I cnage the code below to post the same details except to
different worksheets depending on the value in Report K6?
For example, if Report K6 = London, then post the values (as below) to
a sheet called "Database London". If Report K6 = Paris, then post the
values (as below) to a sheet called "Database Paris".
Thanks
Sub Database_Post()
Dim r As Long, c As Long, rng As Range
Dim MyValues(9, 5), MyHeaders(3), MyColumns
Application.ScreenUpdating = False
Set rng = Sheets("Database").Cells(65536, "E").End(xlUp).Offset(1,
0)
MyColumns = Array("A", "C", "H", "K", "M")
For r = 0 To 8
For c = 0 To UBound(MyColumns)
MyValues(r, c) = _
Sheets("Report").Cells(18 + 5 * r, MyColumns(c)).Value
Next c
Next r
With Sheets("Report")
MyHeaders(0) = .Range("E6").Value
MyHeaders(1) = .Range("K6").Value
MyHeaders(2) = .Range("E9").Value
MyHeaders(3) = .Range("E12").Value
End With
rng.Resize(10, 5).Value = MyValues
On Error Resume Next
rng.Offset(0, -4).Resize(rng.Parent.Cells(65536, "E") _
.End(xlUp).Row - rng.Row + 1, 4) = MyHeaders
Sheets("Database").Select
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Range("A1").Select
Sheets("Report").Select
Range("A1").Select
End Sub