formatting cells (borders, patterns, etc.)

K

Kevin

Is it possible to format a cell using VBA code

My code include the following

DatabaseWorksheet.Cells(DestinationRow, 1).Value = AssignDat

At the time this code is executed the cell is not formatted. How would I modify this code so that, in addition to being populated with AssignDate, borders and a pattern would be added

Thanks

Kevin
 
D

Don Guillett

Here is an example. Just make a manual selection or uncomment the range and
modify to suit.

Sub Addborders()'Make selection and execute
Dim myBorders
Dim i As Integer
myBorders = Array(, xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlEdgeBottom,
xlInsideVertical, xlInsideHorizontal)
For i = 1 To UBound(myBorders)
'Range("h2:J6").Select
With Selection.Borders(myBorders(i))
.LineStyle = xlContinuous
End With
Next
End Sub

--
Don Guillett
SalesAid Software
(e-mail address removed)
Kevin said:
Is it possible to format a cell using VBA code?

My code include the following.

DatabaseWorksheet.Cells(DestinationRow, 1).Value = AssignDate

At the time this code is executed the cell is not formatted. How would I
modify this code so that, in addition to being populated with AssignDate,
borders and a pattern would be added?
 
T

Tom Ogilvy

The easiest way to see the code (and the possibilities) is to turn on the
macro recorder (tools=>Macro=>Record a new macro)

then perform the actions manually.

then turn off the recorder and look at the code.

this will give you the properties, methods and constant arguments you need.
You can then use them in your code.

--
Regards,
Tom Ogilvy


Kevin said:
Is it possible to format a cell using VBA code?

My code include the following.

DatabaseWorksheet.Cells(DestinationRow, 1).Value = AssignDate

At the time this code is executed the cell is not formatted. How would I
modify this code so that, in addition to being populated with AssignDate,
borders and a pattern would be added?
 
L

Lars Kofod

Sub FormatRange()
With Worksheets("Ark1").Cells(DestinationRow, 1)
.Value = AssignDate
.Font.Bold = True
.Interior.Color = RGB(255, 255, 0)
....
....
End With
End Sub
-----Original Message-----
Is it possible to format a cell using VBA code?

My code include the following.

DatabaseWorksheet.Cells(DestinationRow, 1).Value = AssignDate

At the time this code is executed the cell is not
formatted. How would I modify this code so that, in
addition to being populated with AssignDate, borders and
a pattern would be added?
 
T

Tom Ogilvy

Just to mention, the recorder will record settings for all attributes of the
cell. You only need to select those attributes you want to set/change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top