Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vba recordset for Excel programming

I have managed to get all the information from a query into an excel
spreassheet using VBA. I am not sure how to set the range of a recordset or
how to provide columns on the side of the report to calculate based on the #
of records. For example, I have all the records (a:h) and in column (i) I
need to calculate (a+b).
How do I do this with VBA. The number of records from the query will
fluctuate every time the report is ran.
How do I set the function in a blank cloumn based on how many records there
are?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Vba recordset for Excel programming

Either add this code to your routine that gets the information in VBA or
create a new Sub and use this code in it.

You'll need to change the Range("A1").Select to choose the first cell in
column A where your data starts. It is set up now to build the formulas in
column I.

Dim LoopCounter As Long
'select first cell with something to add in it
'that is in column A
Range("A1").Select
If IsEmpty(ActiveCell) Then
Exit Sub
End If
'change 8 to column # you want formula in
'C = 3, D= 4, ... I =8, J=9, etc.
'special case - chose last in list
If IsEmpty(ActiveCell.Offset(1, 0)) Then
ActiveCell.Offset(0, 8).Formula _
= "=A" & ActiveCell.Row & "+B" & ActiveCell.Row
Exit Sub
End If
For LoopCounter = ActiveCell.Row To _
ActiveCell.End(xlDown).Row
'change all 8s to column # you want formula in
'C = 3, D= 4, ... I =8, J=9, etc.
ActiveCell.Offset(LoopCounter - ActiveCell.Row, 8).Formula _
= "=A" & ActiveCell.Offset(LoopCounter - ActiveCell.Row, 8).Row _
& "+B" & ActiveCell.Offset(LoopCounter - ActiveCell.Row, 8).Row
Next

Hope you find this helpful.
"marthasanchez" wrote:

I have managed to get all the information from a query into an excel
spreassheet using VBA. I am not sure how to set the range of a recordset or
how to provide columns on the side of the report to calculate based on the #
of records. For example, I have all the records (a:h) and in column (i) I
need to calculate (a+b).
How do I do this with VBA. The number of records from the query will
fluctuate every time the report is ran.
How do I set the function in a blank cloumn based on how many records there
are?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Vba recordset for Excel programming

Search the help file for topic CopyFromRecordset; it might be what you are
looking for.
Why not calculate (a+b) as another column in your SQL?

Reply
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
DAO Recordset in Excel Andy Excel Programming 2 October 3rd 04 12:13 AM
adodb.recordset with excel nate axtell Excel Programming 14 June 11th 04 01:32 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset in Excel Newbie Excel Programming 3 February 12th 04 12:34 PM
Display a Recordset in Excel Alex A Excel Programming 5 October 31st 03 10:13 PM


All times are GMT +1. The time now is 05:47 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"