Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macros project

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macros project

Are you talking about using a Macro or VBA? It would seem you need a Loop to
achieve this, but I believe we would need more information about exactly what
your looking for.


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Macros project

You'll have to substitute the print range and the sheet names to the sheet
names and print range you're using. I've used the following values:

SheetWithRefNums is the sheet containing the reference numbers
SheetToPrintFrom is the sheet you're pasting the reference number to and
printing from.
RangeToPrint is the range in SheetToPrintFrom that you're printing

Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("SheetWithRefNums")
Set ws2 = wb.Worksheets("SheetToPrintFrom")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ws2.Activate
Range("A1").Select
ActiveCell.Value = strRefNum
ActiveSheet.PageSetup.PrintArea = "RangeToPrint"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macros project

Kevin,

This is helps, but I need the reference cells to be cut out individually. I
need the first reference number cut, pasted onto sheet 2, and then sheet 2
printed. Following this I need the second reference number cut, pasted and
printed...Number 3 cut pasted printed... Can you show me how to code this?

"Kevin B" wrote:

You'll have to substitute the print range and the sheet names to the sheet
names and print range you're using. I've used the following values:

SheetWithRefNums is the sheet containing the reference numbers
SheetToPrintFrom is the sheet you're pasting the reference number to and
printing from.
RangeToPrint is the range in SheetToPrintFrom that you're printing

Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("SheetWithRefNums")
Set ws2 = wb.Worksheets("SheetToPrintFrom")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ws2.Activate
Range("A1").Select
ActiveCell.Value = strRefNum
ActiveSheet.PageSetup.PrintArea = "RangeToPrint"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Macros project

This modified version does the cut & paste that you need it to do. Locate
the following lines and make the appropriate modifications to match your
particular spreadsheet coordinates:

1. Set ws1 = wb.Worksheets("Sheet1")
2. Set ws2 = wb.Worksheets("Sheet2")
3. ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"

Item 1 and Item 2 are the source sheet containing the reference numbers and
3 is the target sheet containing the print range.


Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("Sheet1")
Set ws2 = wb.Worksheets("Sheet2")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ActiveCell.Cut
ws2.Activate
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop

Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

Kevin,

This is helps, but I need the reference cells to be cut out individually. I
need the first reference number cut, pasted onto sheet 2, and then sheet 2
printed. Following this I need the second reference number cut, pasted and
printed...Number 3 cut pasted printed... Can you show me how to code this?

"Kevin B" wrote:

You'll have to substitute the print range and the sheet names to the sheet
names and print range you're using. I've used the following values:

SheetWithRefNums is the sheet containing the reference numbers
SheetToPrintFrom is the sheet you're pasting the reference number to and
printing from.
RangeToPrint is the range in SheetToPrintFrom that you're printing

Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("SheetWithRefNums")
Set ws2 = wb.Worksheets("SheetToPrintFrom")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ws2.Activate
Range("A1").Select
ActiveCell.Value = strRefNum
ActiveSheet.PageSetup.PrintArea = "RangeToPrint"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macros project

Kevin,

Thanks for helping! This process has helped, and the code works well. I
was wondering if you might be able to help with one more thing: Saving the
documents after printing, allowing for different file names(save as).

Rob

"Kevin B" wrote:

This modified version does the cut & paste that you need it to do. Locate
the following lines and make the appropriate modifications to match your
particular spreadsheet coordinates:

1. Set ws1 = wb.Worksheets("Sheet1")
2. Set ws2 = wb.Worksheets("Sheet2")
3. ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"

Item 1 and Item 2 are the source sheet containing the reference numbers and
3 is the target sheet containing the print range.


Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("Sheet1")
Set ws2 = wb.Worksheets("Sheet2")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ActiveCell.Cut
ws2.Activate
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop

Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

Kevin,

This is helps, but I need the reference cells to be cut out individually. I
need the first reference number cut, pasted onto sheet 2, and then sheet 2
printed. Following this I need the second reference number cut, pasted and
printed...Number 3 cut pasted printed... Can you show me how to code this?

"Kevin B" wrote:

You'll have to substitute the print range and the sheet names to the sheet
names and print range you're using. I've used the following values:

SheetWithRefNums is the sheet containing the reference numbers
SheetToPrintFrom is the sheet you're pasting the reference number to and
printing from.
RangeToPrint is the range in SheetToPrintFrom that you're printing

Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("SheetWithRefNums")
Set ws2 = wb.Worksheets("SheetToPrintFrom")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ws2.Activate
Range("A1").Select
ActiveCell.Value = strRefNum
ActiveSheet.PageSetup.PrintArea = "RangeToPrint"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Macros project

Sorry for the delay, but I didn't have an opportunity to run through my
former posts.

If the save thing is still an issue you can try the following:
================================================== ====
Sub SaveAsOnPrint()

Dim varFileName As Variant

varFileName = Application.GetSaveAsFilename

If varFileName = False Then Exit Sub

ActiveWorkbook.SaveAs Filename:=varFileName

End Sub
================================================== ====
--
Kevin Backmann


"RobMack" wrote:

Kevin,

Thanks for helping! This process has helped, and the code works well. I
was wondering if you might be able to help with one more thing: Saving the
documents after printing, allowing for different file names(save as).

Rob

"Kevin B" wrote:

This modified version does the cut & paste that you need it to do. Locate
the following lines and make the appropriate modifications to match your
particular spreadsheet coordinates:

1. Set ws1 = wb.Worksheets("Sheet1")
2. Set ws2 = wb.Worksheets("Sheet2")
3. ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"

Item 1 and Item 2 are the source sheet containing the reference numbers and
3 is the target sheet containing the print range.


Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("Sheet1")
Set ws2 = wb.Worksheets("Sheet2")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ActiveCell.Cut
ws2.Activate
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.PageSetup.PrintArea = "$A$1:$B$1"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop

Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

Kevin,

This is helps, but I need the reference cells to be cut out individually. I
need the first reference number cut, pasted onto sheet 2, and then sheet 2
printed. Following this I need the second reference number cut, pasted and
printed...Number 3 cut pasted printed... Can you show me how to code this?

"Kevin B" wrote:

You'll have to substitute the print range and the sheet names to the sheet
names and print range you're using. I've used the following values:

SheetWithRefNums is the sheet containing the reference numbers
SheetToPrintFrom is the sheet you're pasting the reference number to and
printing from.
RangeToPrint is the range in SheetToPrintFrom that you're printing

Sub PrintRefNums()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lRow As Long
Dim strRefNum As String

Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("SheetWithRefNums")
Set ws2 = wb.Worksheets("SheetToPrintFrom")

ws1.Activate
Range("A1").Select
lRow = 1
strRefNum = ActiveCell.Value

Do Until strRefNum = ""
Cells(lRow, 1).Select
strRefNum = ActiveCell.Value
ws2.Activate
Range("A1").Select
ActiveCell.Value = strRefNum
ActiveSheet.PageSetup.PrintArea = "RangeToPrint"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
Collate:=True
lRow = lRow + 1
ws1.Activate
Loop
Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

End Sub

--
Kevin Backmann


"RobMack" wrote:

I am wondering how to get a process, contained in Microsoft Excel, to repeat
itself. I need to cut a reference number from sheet one, paste into sheet
two, and then print sheet two. There are multiple reference numbers in sheet
one. I don't know how to get the process to repeat so that all reference
numbers get cut out and then pasted?


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
error "The macros in this project are disabled" 300bps Excel Programming 3 January 17th 06 09:39 PM
With VBA from Excel: Open Project, extract resource list and copy it to a worksheet, close project. Tony Excel Programming 1 October 18th 05 03:53 PM
Macros in this project are disabled???? jvoortman Excel Worksheet Functions 3 December 3rd 04 11:31 PM
Message: The macros in this project are disabled. Marston Excel Programming 2 October 12th 04 05:46 PM
Macros in this project are disabled Ceej Excel Programming 2 December 11th 03 06:54 PM


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