PDA

View Full Version : Cell Formatting VBA Help



lcfc2kotmail
02-02-2008, 03:38 AM
Hi I have a loop within my main program

For i = 1 To 10
For j = 1 To 20

Worksheets(2).Cells(1, i) = arraya(i)
Worksheets(2).Cells(j + 1, i) = arrayb(i,j)
Next j
Next i

hi this loop works and outputs my data as needed from my 2 arrays, arraya contains a string of names and arrayb contains data.


However I want to while its outputtingthese to make the names autofit in the columns across and also make them bold(i.e. the first cells statemnt)

From the second statement where it outputs the data, I would like this data to be centred and to 2DP, many thanks if anybody could suggested anything

Bob Phillips
02-02-2008, 04:01 AM
For i = 1 To 10
For j = 1 To 20

With Worksheets(2).Cells(1, i)

.Value = arraya(i)
End With

With Worksheets(2).Cells(j + 1, i)

.Value = arrayb(i, j)
.NumberFormat = "#,##0.00"
End With
Next j
Next i
Worksheets(2).Columns(1).Resize(, 10).AutoFit

lcfc2kotmail
02-02-2008, 04:16 AM
Hi,

Many thanks for that, how doyou get the top line to just be bold and/or centred.

Thank you for your help!

Bob Phillips
02-02-2008, 04:37 AM
With Worksheets(2)

For i = 1 To 10
For j = 1 To 20

With .Cells(1, i)

.Value = arraya(i)
End With

With .Cells(j + 1, i)

.Value = arrayb(i, j)
.NumberFormat = "#,##0.00"
End With
Next j
Next i

.Columns(1).Resize(, 10).AutoFit

With .Rows(1)

.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
End With