View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Bruce Roberson Bruce Roberson is offline
external usenet poster
 
Posts: 47
Default Challenging Formula in VB

Well, I gave up the idea of embedding the formulas in VB.
Most of these formulas are bad enough as it is in the
spreadsheet itself without trying to make them into
strings or actual formulas inside the VB sub. I tried the
string method as best I could construct it but that was
too hard also. I just ended up constructing the text
itself in spreadsheet cells and then I assemble it a
record at a time in a range called "Workarea" and then
finally I copy the completed text a well record at a time
over to the report sheet where it resides in columnar
fashion. The detailloop you can see below is the longest
SUB of the project

This loop for the detail works, but I am sure you will
find the coding structure to be horrendously inefficient.
I still have too many selects as I work between sheets and
ranges to start my copying.

I keep having to select my worksheet on one line, and then
my range on another line. If I don't, it keeps giving me
this run time error '1004' Select method of range class
failed. And, to that, I say a big "WHATEVER!!!", like I
know why it does that <LOL But that is why the sheet is
selected on one line (see line 7 of the loop), and then I
selected the range on a separate line. Otherwise it speaks
that Greek mumbo jumbo to me.

There are three basic worksheets I'm working between. The
sheet "import" is where I've imported the row wise data
from my database Alpha V. The sheet "Data_Assembly" is
where I assemble all those awful formulas you got a peak
at yesterday, and its where I have a gob of spreadsheet
ranges. And it also is where I temporarily copy the
results of the data assembly into a spreadsheet ranged
called "Workarea".

Finally, it copies structured data from the workarea into
the sheet called "report". This is where I'm laying out my
report to the state, and the layout on this sheet is
straight text in columnar arrangement. It will be copied
and pasted to another file and saved as a TXT file when
this thing is finished.

So, those are my three sheets in the workbook that are
referred to in this looping, Import, Data_Assembly, and
Report.

Here is the detailloop at this point:


Sub detailloop()
Dim Crows As Long
Range("rowsum").Value = 1
Sheets("Import").Select
Crows = Cells(1, 1).End(xlDown).Row
For i = 1 To Crows - 1
Sheets("Data_Assembly").Select
Range("Workarea").Select
ActiveCell.Value = Range("Detailloop").Offset(0, 0)
ActiveCell.Offset(1, 0).Value =
Range("Detailloop").Offset(1, 0)
ActiveCell.Offset(2, 0).Value =
Range("Detailloop").Offset(2, 0)
ActiveCell.Offset(3, 0).Value =

And so on like this through the 13th offset then I do a
check of a True false range in the if statement below:

If Range("Do_lse_use") Then
ActiveCell.Offset(14, 0).Value =
Range("lease_use").Offset(0, 0)
ActiveCell.Offset(15, 0).Value =
Range("lease_use").Offset(1, 0)

This part goes on till the offset in range "lease use" is
at 13.


Else
GoTo copyrecords
End If
copyrecords:
Range(ActiveCell, ActiveCell.End(xlDown)).Copy
Sheets("Report").Select
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveCell.PasteSpecial xlPasteValues
Worksheets("Data_Assembly").Select
Range("Workarea").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Clear
Range("Row").Value = Range("Row").Value + 1
If Range("New_Prmo") Then
Range("rowsum").Value = Range("Rowsum").Value + 1
Call summonth
Else
End If
Next
End Sub