|
-
Aug 6th, 2007, 01:36 PM
#1
Thread Starter
Hyperactive Member
VB 6.0 - Excel spreadsheet - split a record so that it writes on two separate rows
Hi everyone,
I have an on-going display problem in another thread("#######") and I thought of a way to solve this problem and eliminate all the headaches:
Looking at the code below, you'll notice that all the field headers are on the same row: example: Firstname Lastname Salary Comments
What if I split the record so that firstname, lastname Salary are written on the same line(row) and the comments is written on the next line(row) by itself and then I can merge the comment row with other cells so there's enough room for all the data to display?
This is how I want the records to display:
Firstname Lastname Salary
Jack John 5,000.00
Comments:
"This employee is over 50 years old and have put in 25 years in this organization"
etc.
Do you understand where I'm going with this?
What is the code I can use to accomplish the above format.
Below is the module that writes the records on the spreadsheet:
Code:
ii = 6
Do Until rsin.EOF = True
ii = ii + 1
xlWksht.Cells(ii, 1).Value = rsin![Req No]
xlWksht.Cells(ii, 2).Value = rsin![Description]
xlWksht.Cells(ii, 3).Value = rsin![P L] & Chr(10) & rsin![Pgmr2] & Chr(10) & rsin![Pgmr3]
xlWksht.Cells(ii, 4).Value = rsin![ClientName] & Chr(10) & rsin![Status]
xlWksht.Cells(ii, 5).Value = "-" & Chr(10) & rsin![Per Hrs]
xlWksht.Cells(ii, 6).Value = rsin![Hours] & Chr(10) & rsin![Tot Hrs]
xlWksht.Cells(ii, 7).Value = rsin![Start Date] & Chr(10) & rsin![Start Date]
xlWksht.Cells(ii, 8).Value = rsin![End Date] & Chr(10) & rsin![End Date]
xlWksht.Cells(ii, 9).Value = "'" & rsin![Comments]
rsin.MoveNext
Loop
Thanks.
GiftX
-
Aug 6th, 2007, 01:40 PM
#2
Thread Starter
Hyperactive Member
Re: VB 6.0 - Excel spreadsheet - split a record so that it writes on two separate rows
Hi everyone,
I have an on-going display problem in another thread("#######") and I thought of a way to solve this problem and eliminate all the headaches:
Looking at the code below, you'll notice that all the field headers are on the same row: example: Firstname Lastname Salary Comments
What if I split the record so that firstname, lastname Salary are written on the same line(row) and the comments is written on the next line(row) by itself and then I can merge the comment row with other cells so there's enough room for all the data to display?
This is how I want the records to display:
Firstname Lastname Salary
Jack John 5,000.00
Comments:
"This employee is over 50 years old and have put in 25 years in this organization"
etc.
Do you understand where I'm going with this?
What is the code I can use to accomplish the above format.
Below is the module that writes the records on the spreadsheet:
Code:
Code:
ii = 6
Do Until rsin.EOF = True
ii = ii + 1
xlWksht.Cells(ii, 1).Value = rsin![Req No]
xlWksht.Cells(ii, 2).Value = rsin![Description]
xlWksht.Cells(ii, 3).Value = rsin![P L] & Chr(10) & rsin![Pgmr2] & Chr(10) & rsin![Pgmr3]
xlWksht.Cells(ii, 4).Value = rsin![ClientName] & Chr(10) & rsin![Status]
xlWksht.Cells(ii, 5).Value = "-" & Chr(10) & rsin![Per Hrs]
xlWksht.Cells(ii, 6).Value = rsin![Hours] & Chr(10) & rsin![Tot Hrs]
xlWksht.Cells(ii, 7).Value = rsin![Start Date] & Chr(10) & rsin![Start Date]
xlWksht.Cells(ii, 8).Value = rsin![End Date] & Chr(10) & rsin![End Date]
xlWksht.Cells(ii, 9).Value = "'" & rsin![Comments] <=== This to display on the next line (Row)
rsin.MoveNext
Loop
Thanks.
GiftX
-
Aug 7th, 2007, 05:33 AM
#3
Re: VB 6.0 - Excel spreadsheet - split a record so that it writes on two separate rows
vb Code:
Do Until rsin.EOF = True
ii = ii + 2
xlWksht.Cells(ii, 1).value = rsin![Req No]
xlWksht.Cells(ii, 2).value = rsin![Description]
xlWksht.Cells(ii, 3).value = rsin![P L] & Chr(10) & rsin![Pgmr2] & Chr(10) & rsin![Pgmr3]
xlWksht.Cells(ii, 4).value = rsin![ClientName] & Chr(10) & rsin![Status]
xlWksht.Cells(ii, 5).value = "-" & Chr(10) & rsin![Per Hrs]
xlWksht.Cells(ii, 6).value = rsin![Hours] & Chr(10) & rsin![Tot Hrs]
xlWksht.Cells(ii, 7).value = rsin![Start Date] & Chr(10) & rsin![Start Date]
xlWksht.Cells(ii, 8).value = rsin![End Date] & Chr(10) & rsin![End Date]
xlWksht.Cells(ii + 1, 1).value = "'" & rsin![Comments]
rsin.MoveNext
Loop
this will put the comment on the next line for each record, you may need to change the initial value of ii form 6 to 5
if you want to put headings for each record, then each record will take four lines instead of 2, but is not hard to do
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 7th, 2007, 09:35 AM
#4
Thread Starter
Hyperactive Member
Re: VB 6.0 - Excel spreadsheet - split a record so that it writes on two separate rows
Hi westconn1,
okay, that objective is been acheived, but the spreadsheet display looks screwy: The first batch of data writes on the first line(row) and the comments field writes on the next line(row)..... good.
Display problem: the comment line is written on column A. because the data in that column is huge(Length of over 2000) the row height is excessively too much. my suggestion is to cells merge so that the data can spread accross to other unused cells on that row.
I am using this code:
Code:
xlWksht.Range("A2:K2").MergeCells = True
to merge some cells to allow the long text in that row to display properly.
How can do the same for all the "comments" line?
I do appreciate your help.
GiftX.
-
Aug 7th, 2007, 04:52 PM
#5
Re: VB 6.0 - Excel spreadsheet - split a record so that it writes on two separate rows
don't have time to try now, but you can try increasing the width of individual cells that contain comment
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|