Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - How to Write to Specific Worksheets

I am using VBA to enter data into cells in Excel 2000. I have not been able
to figure out how to get the relevant data to the first worksheet, then
switch to the second worksheet and enter that relevant data.

Below is simplified code sample of what I am trying to do:


Dim objExcel As New Excel.Application
Set objExcel = New Excel.Application
objExcel.SheetsInNewWorkbook = 2
Dim objWBK As Excel.Workbook
Set objWBK = objExcel.Workbooks.Add
Dim objWKS As Excel.Worksheet
Set objWKS = objWBK.Worksheets.Add
objWBK.Worksheets(1).Name = "By INVOICE"
objWBK.Worksheets(2).Name = "By PROD LINE"

objWBK.SaveAs "BatchPayment_" & Format(Date, "mmddyyyy")

' OK SO FAR

' THIS CORRECTLY WRITES THE DATA TO THE FIRST WORKSHEET

objWKS.Cells(1, 1).Value = "Company XXX Inc."
objWKS.Cells(2, 1).Value = "Wire Detail by Invoice Number"
objWKS.Cells(3, 1).Value = "Transfer Date: " & Format(Date, "dd-mmm-yyyy")

' THIS IS SUPPOSED TO WRITE TO THE SECOND WORKSHEET
' BUT IT IS OVERWRITING THE INFO ON THE FIRST SHEET

' objWBK.Worksheets(2).Activate

objWKS.Cells(1, 1).Value = "COmpany XXX Inc. Page 2"
objWKS.Cells(2, 1).Value = "Wire Detail by Product Group"
objWKS.Cells(3, 1).Value = "Transfer Date: " & Format(Date, "dd-mmm-yyyy")

etc.

How can I get write the 2nd block to the 2nd sheet?

Many thanks,
Mike Thomas




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - How to Write to Specific Worksheets

Why don't you just call that specific sheet:

Worksheets("By INVOICE").cells(1,1).Value = "COmpany XXX Inc. Page 2"

If the worksheets are all in the same workbook you don't even have t
define them. You can just call them like above.

Hope this helps

--
Message posted from http://www.ExcelForum.com

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
How do I write an array to include all worksheets in a workbook? Jodie Excel Worksheet Functions 8 October 13th 09 04:06 PM
Write a formula using two arrays, across two worksheets Susan Excel Worksheet Functions 11 July 29th 08 05:30 PM
Need to test for a specific text string and write value to another Pyramid 36 Excel Worksheet Functions 2 August 3rd 07 12:55 AM
how to write function to find max deviation from specific number . barbdee Excel Worksheet Functions 2 December 16th 05 02:10 AM
select lines from multiple worksheets and write to new worksheet rem Excel Worksheet Functions 1 September 15th 05 03:35 PM


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