PC Review


Reply
Thread Tools Rate Thread

Could Someone Explain this Code

 
 
Sean
Guest
Posts: n/a
 
      30th Mar 2007
Could someone explain the code below? I know it takes the values that
are in Report E6;E9 and E12 and posts them on a sheet called Database,
but where I'm unsure is that it posts these on the row below the last
entries, but I don't know which Column on the Database sheet controls
this. What I wish to do is modify the particular column to action
"Post the entries on the row below the last value entered in Column F
on the Database sheet.

Thanks


Sub Database_Post()
Dim r As Long, c As Long, rng As Range
Dim MyValues(9, 5), MyHeaders(2), MyColumns
Application.ScreenUpdating = False

Set rng = Sheets("Database").Cells(65536, "D").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("E9").Value
MyHeaders(2) = .Range("E12").Value
End With
rng.Resize(10, 5).Value = MyValues
On Error Resume Next
rng.Offset(0, -3).Resize(rng.Parent.Cells(65536, "D") _
.End(xlUp).Row - rng.Row + 1, 3) = MyHeaders

Sheets("Database").Select
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit

Sort

Range("A1").Select
Sheets("Report").Select
Range("A1").Select

End Sub

 
Reply With Quote
 
 
 
 
merjet
Guest
Posts: n/a
 
      30th Mar 2007
It puts MyHeaders based on rng, which is earlier set in Column D.
So change Cells(65536, "D") to Cells(65536, "F").

Hth,
Merjet

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      31st Mar 2007
On Mar 30, 6:04 pm, "merjet" <mer...@comcast.net> wrote:
> It puts MyHeaders based on rng, which is earlier set in Column D.
> So change Cells(65536, "D") to Cells(65536, "F").
>
> Hth,
> Merjet


Thanks Merjet, I tried that and my values that I expected to be posted
in Column D ended up in Column H. Then I changed this rng.Offset(0,
-3).Resize(rng.Parent.Cells(65536, "F") _ TO rng.Offset(0,
-5).Resize(rng.Parent.Cells(65536, "F") _
But then the first 3 Columns posted correctly i.e. A; B and C but the
remaining Columns were ncorrect offset by 2 columns i.e. Column D data
is in Column F etc


 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      31st Mar 2007
Change: rng.Resize(10, 5).Value = MyValues

To: rng.Offset(0, -2).Resize(10, 5).Value = MyValues

Hth,
Merjet

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please explain code =?Utf-8?B?S2FyZW4gTWNLZW56aWU=?= Microsoft Excel Programming 3 12th Mar 2007 12:04 PM
Would someone explain what this code does? John Smith Microsoft Excel Programming 0 6th Dec 2006 01:02 AM
Explain Code brad Microsoft Access 1 30th Sep 2003 07:17 PM
Re: please can someone explain the following code. suzy Microsoft ASP .NET 3 31st Jul 2003 03:07 PM
Re: please can someone explain the following code. suzy Microsoft C# .NET 3 31st Jul 2003 03:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:04 AM.