?
Solved

Is this possible, what I'd like to do with Excel spreadsheet with VB?

Posted on 2004-08-13
10
Medium Priority
?
145 Views
Last Modified: 2010-05-02
Hi all,
I currently do this manually and I was wondering if I can automate it.
------------------
What I do manually:
* export a txt file with 3 types of rows (active, pending, sold) from VB program.
* open the txt file, tell it what delimiter etc into a spreadsheet
* open a Template Excel spreadsheet with formatted titles, formulas etc.
* copy "active" type rows (0 to N rows).
* paste those rows to a line following the title "active" in column A
* copy formula line to those rows just pasted
* repeat for other 2 types of rows (pending, sold).

100 points for a believable good yes/no answer with some details.
Name your points to actually give me some code to do this.
Thanks,
Phil
0
Comment
Question by:spoowiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 8

Expert Comment

by:SNilsson
ID: 11795563

You can try this program (30 days free) and see if it can mimic your steps:

http://www.macroexpress.com/
0
 

Author Comment

by:spoowiz
ID: 11795914
thanks snilsson, but i don't think it'll work.
i have an unknown number of rows to copy/paste.
i think what i need is a VB code to manipulate the "template spreadsheet".
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 11796017


Maybe you can open the exported text file via VBA (Excel) and insert the row's in the .Xla file, do you know how to code in VBA ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:spoowiz
ID: 11796129
no, don't know vba, but willing to learn.
however, seems like if vba can do it, i would think vb can also; and directly from recordset values instead using an intermediary txt file.
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 11796526

"i would think vb can also; and directly from recordset values instead using an intermediary txt file."

Absolutely, no problem there, post the code that create the textfile and I can start modify it to Excel export.


You say 'recordset values' seems like you have access to the database.
If so you can get the values directly from the database, there really is no need to involve VB, unless other operations is done in the VB program.



0
 

Author Comment

by:spoowiz
ID: 11796839
Yes, I get values from the database, but need to do calculations etc for the spreadsheet.
Since the end-result spreadsheet needs a lot of formatting and formulas, I think the "template" idea would work best.
What I'd need to do using VB is:
1. Open the template spreadsheet
2. Search for a row with string "Active" in column A.
3. Insert as many rows as there is from the database/calculated values under that row.
(I'd need to save the row numbers so I can apply the formatting/formulas to those rows, hopefully from another row in template.)
4. Copy a row from the template and "paste special... formatting and formula" to the rows added in #3.

Repeat #2-4 with string "Pending" and "Sold".

Name your points if you can give me a basic code able to accomplish the above. This will not only be useful, it'll be a great learning sample for me. Thanks.
p.s. Need to leave for the afternoon.
0
 
LVL 8

Accepted Solution

by:
SNilsson earned 400 total points
ID: 11798917

Okey, first you will need a reference in VB to  have a reference to the Microsoft Excel Object.


Dim oExcel as Excel.Application
Dim lngRetVal As Long
Dim strfile As String

strfile = "MyTemplate.xls"   ' xla maybe ?

Set oExcel = New Excel.Application

oExcel .Workbooks.Open strfile

____________________________________________________________

Next you need to find the row with the value 'Active' in col a (on sheet ?)

____________________________________________________________
Dim oCell As Excel.Range
Dim lRow As Long
Dim iCounter As Integer

For Each oCell In Range("A:A")
    If oCell.Value = "Active" Then
        oCell.Select
        lRow = oCell.Row
        Exit For
    End If
Next


Do Until myRecordset.EOF
    lRow = lRow + 1
    Range("A" & lRow).Activate
    ActiveCell.Value = myRecordset("MyDBcolumn").Value
Loop


Let's start with this for now, and once you got it to work we move on to the copy/paste and the other columns, I would really like to have a look on the vb code that create the text file also, so I can help you integrate the new code.
(I dont have VB installed right now, so be patient in case of errors I cant test it)
 
0
 

Author Comment

by:spoowiz
ID: 11800752
sn, thanks for taking the time. i'm getting ready to go away for 1.5 weeks, so can't do anything now. will do when i get back.
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 11800920

Allrighty, have good trip and see you then.
0
 

Author Comment

by:spoowiz
ID: 11991919
snilsson, i'm back, however, as i was away, i decided to accomplish my task using another method. i'm giving you points anyway because i've learned something from your code. thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question