|
-
Aug 10th, 2007, 07:39 PM
#12
Re: VB6 - Merge Cells in spreadsheet
the hardcoded loop was just to fix the sample sheet and not needed when populating the sheet
the first post (1 line) should put all the data on one line
this code should get the display just as you want it
autofit did not work for the height of the row, so i had to calculate the height manually, this loop is to convert the sample sheet, but you should be able to incorporate it into your code to populate the sheet, rather than as a separate loop
vb Code:
Set s = Sheets("TblBiWeeklyPeriodExport")
For a = 8 To s.UsedRange.Rows.Count Step 2 ' first cell with comment to end
With s.Range(Cells(a, 1), Cells(a, 8))
If IsEmpty(s.Range("a" & a)) Then Exit For 'your used range was well below the data
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
' .AddIndent = False
.IndentLevel = 0
' .ShrinkToFit = False
.MergeCells = True
w = 0
For Each c In s.Range("A8:h8"): w = w + c.ColumnWidth: Next
.RowHeight = .RowHeight * Len(s.Range("A" & a).Text) / w
End With
Next
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
|