View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Offset and ActiveCell

...ERROR on the following line. Msg: Object doesn't support this
property or method

.ActiveCell.Offset(0, icolumn).Activate


For the above error, just remove the dot in front of the ActiveCell
reference. Putting the dot in makes the ActiveCell try and reference the
ActiveSheet... the ActiveSheet does not have an ActiveCell property (hence
the error)... the ActiveCell is automatically the active cell on the active
sheet (the active cell cannot be located on a non-active sheet). So, make
the above line this...

ActiveCell.Offset(0, icolumn).Activate

--
Rick (MVP - Excel)


"Pendragon" wrote in message
...
Office03

Hey gang,

Have tried to get some assistance in the Access group with limited success
for formatting, but I need some VBA help in referencing Excel from Access.

All code is in Access. I am looping through a recordset and writing data
to
an Excel template. The data is being written down-then-across from column
to
column. "A2" is always the starting point and I am using an offset to move
to
each column and then move downward to write data.

I am having problems setting the reference to the new cell (activating the
cell) in using Offset and then being able to write data to that cell and
format it appropriately.

Any help, clean-up, suggestions are appreciated!

I've eliminated working code to shorten the post but have kept (and
double-checked) all paired IF, WITH, etc., statements

...Working code before this, dim statements, etc.

Set objWkbk = objExcel.workbooks.Open(stTemplate)
x = 0
y = 1

...working code...

Set rs = db.OpenRecordset(sSQL)
stCell = "A2"
rs.MoveFirst

With objWkbk
.sheets("Sheet1").Select
.sheets("Sheet1").Activate
.sheets("Sheet1").Name = stSheetName
irow = 2
icolumn = 1
Do While Not rs.EOF
icolumn = icolumn + x
CName = rs("CourtName")
.....series of IF statements to set variables......

With .ActiveSheet

...ERROR on the following line. Msg: Object doesn't support this property
or
method

.ActiveCell.Offset(0, icolumn).Activate

With ActiveCell
.Value = CName
.HorizontalAlignment = xlcenter
.Font.Bold = True
End With

CID = rs("CourtID")
Do While CID = rs("CourtID")
TID = rs("MatchTimeID")
Do While TID = rs("MatchTimeID")
....write data here (once I get the above problem
resolved)....
Loop
TID = -1
Loop
End With
CID = -1
x = x + 1
Loop
End With