LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to write a vba loop for Excel

I have the following code for an Excel worksheet, it works on the first try
but it fails on the second time. It returns an error saying "Object variable
or With block variable not set". Thanks

.Range("A6").Select
If Not rs1.BOF Then
rs1.MoveFirst
Do While Not rs1.EOF
strPurchaseOrder = rs1!PurchaseOrder
'Assign Purchase Order to Excel
ActiveCell.Offset(1,
0).Select..............................it fails here. it does not like
ActiveCell in the second try
ActiveCell.Offset(1, 0).FormulaR1C1 = "PURCHASE ORDER:"
ActiveCell.Offset(1, 0).Characters(Start:=1,
Length:=25).Font.Name = "Comic Sans MS"
ActiveCell.Offset(1, 0).Characters(Start:=1,
Length:=25).Font.FontStyle = "Regular"
ActiveCell.Offset(1, 0).Characters(Start:=1,
Length:=25).Font.SIZE = 16

ActiveCell.Offset(0, 1).Select
Range(ActiveCell.Offset(0, 0).Address & ":" &
ActiveCell.Offset(0, 4).Address).Select
Range(ActiveCell.Offset(0, 0).Address & ":" &
ActiveCell.Offset(0, 4).Address).HorizontalAlignment = xlLeft
Range(ActiveCell.Offset(0, 0).Address & ":" &
ActiveCell.Offset(0, 4).Address).MergeCells = True

ActiveCell.FormulaR1C1 = strPurchaseOrder
ActiveCell.Characters(Start:=1, Length:=25).Font.Name =
"Comic Sans MS"
ActiveCell.Characters(Start:=1, Length:=25).Font.SIZE = 16

ActiveCell.Offset(1, -1).Select
Set rs2 = CurrentDb.OpenRecordset("SELECT [Qry_Store
Purchase Order Pull Sheet].* " & _
"FROM [Qry_Store Purchase Order
Pull Sheet] " & _
"WHERE ((([Qry_Store Purchase
Order Pull Sheet].PurchaseOrder)='" & strPurchaseOrder & "'));",
dbOpenSnapshot)
If Not rs2.BOF Then
rs2.MoveFirst
Do While Not rs2.EOF
strHDDescription = rs2!HomeDepotDescription
strSize = rs2!SIZE
strSKU = rs2!SKU
strQuantity = rs2!ShippingQuantity
'Assign Store Purchase Order Details to Excel
ActiveCell.FormulaR1C1 = strHDDescription
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strSize
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strSKU
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strQuantity
ActiveCell.Offset(1, -3).Select
rs2.MoveNext
Loop
rs2.Close
End If
rs1.MoveNext
Loop
rs1.Close
End If


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Excel VBA Write to xls ? Adrian[_7_] Excel Programming 0 August 31st 04 02:23 PM
Loop,Compare,Write Michael168[_75_] Excel Programming 1 May 25th 04 06:41 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"