Excel VBA code under Project

J

Jeff Potts

Is it possible to run the following code snippets from a Microsoft Project
Macr? If it is possible to run the code, how might I convert it or make it
run under Project.

I am exporting timescaledata and would like to do some formatting of the
sheet for the user.

Thanks
Jeff

====================================================Sub SameAsAbove()
'Any blank cell in column A will be changed to be the same as the cell above
it
Dim LastRow As Long
Dim cell As Range
Dim DataRng As Range
LastRow = Cells(Rows.Count, "b").End(xlUp).Row
Set DataRng = Range("b2:b" & LastRow)
For Each cell In DataRng
If cell = "" Then
cell = cell.Offset(-1, 0)
End If
Next cell
End Sub
Sub Select_Conditional_Rows_WithLoop()

Dim col As Range, cell As Range, rng As Range
Set col = Intersect(ActiveSheet.UsedRange, Columns(1))


For Each cell In col
If Right(cell.Value, 5) = "Total" Then
If Not rng Is Nothing Then
Set rng = Union(cell, rng)
Else
Set rng = cell
End If
End If

Next

rng.EntireRow.Select
Selection.Font.Bold = True
End Sub
Sub PrepWork()
Range("A1:A2").Select
Selection.Cut Destination:=Range("B1:B2")
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
End Sub
 
R

Rod Gill

Hi,

Yes with a little modification. You need to establish an Excel application
object and go on from there. Search help for controlling one office
application from another. With Excel already running and a reference set to
the Excel object library you need something like:

dim xlApp as Excel.application

set xlapp=getobject(,"Excel.Application")
Dim LastRow As Long
Dim cell As Excel.Range
Dim DataRng As Excel.Range
LastRow = xlapp.Cells(Rows.Count, "b").End(xlUp).Row
Set DataRng = xlapp.Range("b2:b" & LastRow)
For Each cell In DataRng
If cell = "" Then
cell = cell.Offset(-1, 0)
End If
Next cell
End Sub



--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.project-systems.co.nz/
Email rodg AT project-systems DOT co DOT nz
 

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