LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
billrl34
 
Posts: n/a
Default Macro pulling data from 2 worksheets


I need your help. I have been using a macro to pull data from only one
worksheet, C_Data. My business has expanded and now I have data in 2
worksheets, C_Data and C_Data2, that need to be pulled by the macro.
The original code for the single worksheet data is as follows:

Option Explicit
' How do I return to memory the 'puter power that is used
' by my variables?

' Module Name: NextProduct

' CONTENTS OF THIS MODULE
' 1. NextCookie [Ctrl+Shift+C]
' Calls FunctNextCookie frm keyboard;
' instructs it to un/hide ingreds.
' 1f. FunctNextCookie - FUNCTION
' Runs next SKU thru cookie cost template;
' un/hides rows to display ingreds if so instructed.
' 3. PrintAllProducts [Ctrl+Shift+A]
' Runs each product & prints a copy.
' 4. HideZeroUsage
' Hides any raw & pkg ingrediant items w/ 0 usage for
' currently displayed SKU.

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''

Sub NextCookie()
' Macro recorded 1/3/2002, revised 12/5/2005
'
' Keyboard Shortcut: Ctrl+Shift+C
'
' Will select C_Data sheet, move cursor one cell to right,
' copy, and paste value on cell C5 of Cookie sheet.
'
' Invokes HideZeroUsage.
FunctNextCookie (True)
End Sub

Function FunctNextCookie(Optional blnHide As Boolean)
Sheets("C_Data").Select
Cells(3, ActiveCell.Column).Select
' Moves cursor to row 3.
ActiveCell.Offset(0, 1).Range("A1").Select
' Selects next SKU.
Selection.Copy
Sheets("Cookie").Select
Range("C5").PasteSpecial Paste:=xlValues
' Does not HideZeroUsage if called by ReportAll.
If blnHide = True Then HideZeroUsage
End Function

Sub PrintAllProducts()
' Keyboard Shortcut: Ctrl+Shift+A
Dim bytGo As Byte
Dim objSheet As Object
Dim strDataSource As String

bytGo = MsgBox("Print cost model for every product?", vbYesNo, _
"Print All Products")
' User's opportunity to back out.
Select Case bytGo
Case vbYes
For Each objSheet In Worksheets
' Loops through all sheets.
If objSheet.Name = "C_Data"
' Skips all but data sheets, so Cookies
' get read once.
objSheet.Select
Cells(3, 1).Select
' Starting point for NextCookie.
Do
' Keeps reading to right until it runs out
' of SKUs, then moves onto next sheet.
If WhichPlant = "Cookie" Then
FunctNextCookie (True) ' Runs next
cookie.

End If
' MsgBox Range("C5").Value
' Uncomment to test macro w/o wasting paper.
ActiveWindow.SelectedSheets.PrintOut Copies:=1
' Prints.
objSheet.Select
' Starting point for next iteration of
' NextCookie.
Loop Until ActiveCell.Offset(0,
1).Range("A1").Value = ""
End If
Next objSheet
Case Else
' Do nothing.
End Select
End Sub

Sub HideZeroUsage()
' HOW TO BREAK THIS MACRO
' allowing blank spaces in the
' -- Item Desc ranges (raws)
' -- HLOOKUP(row) ranges for the Item Descs (pkg)

Select Case ActiveSheet.Name = "Cookie"
' prevents macro from running on any sheet but templates.
Case True

Cells.Select
Selection.EntireRow.Hidden = False
Range("A1").Select

' Raws
Select Case ActiveSheet.Name
' positions cursor at start of raw materials
Case "Cookie"
Range("E21").Activate
End Select

Do
Select Case True
Case ActiveCell = 0
Selection.EntireRow.Hidden = True
Case ActiveCell.Offset(0, -3).Value = ""
Selection.EntireRow.Hidden = True
End Select
ActiveCell.Offset(1, 0).Activate
Loop While ActiveCell.Offset(0, -3).Value < 0

' Packaging
Select Case ActiveSheet.Name
' positions cursor at start of raw materials
Case "Cookie"
Range("E133").Activate
End Select
Do
Select Case True
Case ActiveCell.Value = 0
Selection.EntireRow.Hidden = True
Case ActiveCell.Offset(0, -3).Value = ""
Selection.EntireRow.Hidden = True
End Select
ActiveCell.Offset(1, 0).Activate
Loop While ActiveCell.Offset(0, -4).Value < 0

Case Else
End Select
' prevents macro from running on any sheet but templates.
End Sub


--
billrl34
------------------------------------------------------------------------
billrl34's Profile: http://www.excelforum.com/member.php...o&userid=29533
View this thread: http://www.excelforum.com/showthread...hreadid=492822

 
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
sort data on multiple worksheets bill Excel Discussion (Misc queries) 0 November 29th 05 05:52 PM
Macro to break data into worksheets Amy S. Excel Discussion (Misc queries) 7 September 21st 05 03:23 PM
Unique and duplicate data between 2 Excel worksheets Greg Excel Worksheet Functions 0 August 9th 05 12:03 AM
Inserting Filtered RC cell information into other worksheets Dennis Excel Discussion (Misc queries) 10 July 30th 05 01:54 AM
Macro data selection line delete Frantic Excel-er Excel Discussion (Misc queries) 0 May 31st 05 11:46 PM


All times are GMT +1. The time now is 11:27 AM.

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"