Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Microsoft Support > Microsoft Office support
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Microsoft Office support MS Office support forum

Reply
 
LinkBack Thread Tools
Old 06-29-2007, 04:49 AM   #1 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Using a Macro in MS Excel to produce a report

Hi all

I have created an excel spreadsheet that has a series of questions, each having a drop down list in the answer column. Yes, No and N/A are the only answers available.

Is it possible to set up a button that prints a report of all the questions that have been answered No?

If this is possible, how?

Thanks
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 06-29-2007, 06:27 AM   #2 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Hi

Yes, entirely possible.

You would create some code that would check the values in the relevant column, and if all are "No" then print a report. What version of Excel are you using? Is the 'Report' already pre-formatted and ready for printing? What are the relevant ranges? What is the relevant sheet name? What case are the answers - upper case sentence case, lower case? How did you create the drop downs - forms toolbar or Control Toolbox?

Lot's of info required...
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-29-2007, 06:37 AM   #3 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Hi

I will clarify what I need then answer your questions.

1. The code should not pick out if ALL are No. The code should see which ones are NO, see the adjacent question then create a statements in the report based around those questions.

2. I am using Excel 2003

3. I have not started the report.

4. I have uploaded a copy of the workbook which should help you understand the ranges, case and sheet names.

5. The dropdown boxes were created using the Data > Validation > List option


Once created the report must be enabled for each following column.
Attached Files
File Type: zip file check net.zip (7.0 KB, 3 views)
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-01-2007, 02:50 PM   #4 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Hi

Sorry I didn't get a chance to reply sooner.

I've amended your workbook and added a button that will generate a report on a separate sheet. The code looks to see if the answer is no. It then copies that value to column B and copies the corresponding question to column A.

Hope this helps get you started.
Attached Files
File Type: zip file check net.zip (16.0 KB, 27 views)
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 02:19 AM   #5 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

many thanks for your help. im probably being a dope but the button does not do anything when I press it and when i double click it I am sent to visual basic.

A further little guidance if you could?
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 06:12 AM   #6 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Sounds like you may still be in Design Mode. Look on the Control Toolbox toolbar for a blue triangle - you'll need to click it to turn off Design Mode.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 06:44 AM   #7 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

many thanks, I have now got it working.

Is it possibe to have the report open in MS Word instead of an excel sheet?
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-02-2007, 01:40 PM   #8 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

It's possible, but will take me a bit of time and is slightly more complex. I'll get back to you with something whenever I possibly can.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-03-2007, 01:59 AM   #9 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Okey dokes, it would be greatly appreciated.

Ive amended the existing code so that each column has its own create report button. Im fairly advanced at HTML and PHP and a little bit of MySQL and JS so can kinda read between the lines of code of Visual Basic and amend as nec.
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-05-2007, 09:54 AM   #10 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Hi Glaswegian

Have you been able to look at the code?

Forgive me if I come across rude or impatient.

Cheers
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-05-2007, 12:59 PM   #11 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Hi

Apologies - haven't forgotten - real life has rather intruded a bit. I've just got a code glitch to iron out. Should have that sorted in a while.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-05-2007, 01:29 PM   #12 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Hi again

Had an Excel glitch but got around it. I appreciate you've already made some code changes, but this is based on what we had. There are some things to note - there is no error checking, you'll have to manually save the Word doc, there are no headers etc included in the Word doc. If you need any of these things let me know.
Code:
Private Sub CommandButton1_Click()
Dim myRng As Range
Dim c As Range
Dim repRng As Range
Dim wdApp As Word.Application


Set myRng = Range("C6:C35") 'the range on the question sheet that contains Yes/No etc

For Each c In myRng
    If c.Value = "No" Then 'if the answer is No
        With Sheets("Report")
            .Range("B65536").End(xlUp).Offset(1, 0).Value = c.Value 'write the answer to column B
            .Range("A65536").End(xlUp).Offset(1, 0).Value = c.Offset(0, -1).Value 'write the question to column A
        End With
    End If
Next c

Sheets("Report").Columns("A:B").AutoFit 'adjust the cell widths

Worksheets("Report").Range("A2").Select
ActiveCell.CurrentRegion.Copy 'copy the report

Set wdApp = New Word.Application
'create a new instance of Word and add a blank document
With wdApp
    .Documents.Add
    .Visible = True
End With

'paste the data
wdApp.Selection.Paste

Application.CutCopyMode = False

Set wdApp = Nothing

End Sub
Nothing too fancy - still writes the data to the Report sheet, but then opens Word and drops the data into a new Word doc. Just replace your existing code.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 02:01 AM   #13 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Hi

Many thanks, will have a blast at it now.

I know im gonna be pushing my luck, but is there anyway you can reference the report to a word template, instead of a new document?
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 02:09 AM   #14 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Im getting a user-compile error, on line

Dim wdApp As Word.Application
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 06:17 AM   #15 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Quote:
Originally Posted by peteyb View Post
Hi

Many thanks, will have a blast at it now.

I know im gonna be pushing my luck, but is there anyway you can reference the report to a word template, instead of a new document?
I think so...is it a new template or an existing one? I think I can do new, but I'm not so sure on existing. I'm not that good on Word VBA.

Quote:
Originally Posted by peteyb View Post
Im getting a user-compile error, on line

Dim wdApp As Word.Application
Ah - you need to have a reference in Excel to Word's Object Model. Open Excel and press Alt+F11 to open the VB Editor. On the menu bar click on Tools > References and in the dialog box look for Microsoft Word 10.0 Object Library. Check the box and click OK. That should be OK now.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 06:23 AM   #16 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Ive done that, it's number 11.0 on mine.

I am now getting a runtime error '1004' and the debug shows:

Worksheets("Report").Range("A2").Select
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 06:25 AM   #17 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

oh and yes, it is a new template.
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-06-2007, 02:59 PM   #18 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Quote:
Originally Posted by peteyb View Post
Ive done that, it's number 11.0 on mine.

I am now getting a runtime error '1004' and the debug shows:

Worksheets("Report").Range("A2").Select
This is where I had the earlier problem, but in a slightly different way. It's something to do with the way I'm referencing that sheet, but for the life of me I can't work out what it might be.

Leave this with me and I'll work on it over the weekend. I'll also try the template part, but I think I know how to do that.
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-08-2007, 03:37 PM   #19 (permalink)
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
 
Glaswegian's Avatar
 
Join Date: Sep 2005
Location: Glasgow
Posts: 25,497
OS: Win XP Pro SP3 / Win 7 Pro

My System

Blog Entries: 10
Re: Using a Macro in MS Excel to produce a report

Hi

Having now realised where I'd made the code blooper , see if this works for you.
Code:
Private Sub CommandButton1_Click()
Dim myRng As Range
Dim c As Range
Dim repRng As Range
Dim wdApp As Word.Application
Dim wdDoc As Word.Document


Set myRng = Range("C6:C35") 'the range on the question sheet that contains Yes/No etc

For Each c In myRng
    If c.Value = "No" Then 'if the answer is No
        With Sheets("Report")
            .Range("B65536").End(xlUp).Offset(1, 0).Value = c.Value 'write the answer to column B
            .Range("A65536").End(xlUp).Offset(1, 0).Value = c.Offset(0, -1).Value 'write the question to column A
        End With
    End If
Next c

Sheets("Report").Columns("A:B").AutoFit 'adjust the cell widths

With Worksheets("Report")
    .Range("A1", .Range("B65536").End(xlUp)).Copy
End With

Set wdApp = New Word.Application
'create a new instance of Word
wdApp.Visible = True

Set wdDoc = wdApp.Documents.Add(newtemplate:=True) 'add a new template
wdDoc.Activate

'paste the data
wdDoc.Application.Selection.Paste

Application.CutCopyMode = False

Set wdApp = Nothing

End Sub
__________________
Iain - Defender of the Haggis and all things Scottish.
I don't help by PM - post in the Forums.



PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner
Glaswegian is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-09-2007, 02:17 AM   #20 (permalink)
Registered User
 
peteyb's Avatar
 
Join Date: Apr 2007
Posts: 60
OS: xp pro


Re: Using a Macro in MS Excel to produce a report

Hi

Many thanks for the work on the code. This is working as expected.

I didnt quite fully explain myself when I said 'New Template'. I meant New, as in I havent created it yet, not new as in create a new template everytime someone runs a report.

Do you know how to reference an existing template and insert the NO answers into the document? If so, can the template be referenced to a file server, or does it have to be local on the machine?
peteyb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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




All times are GMT -7. The time now is 03:38 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85