Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default For Loop with headers

I'm trying to get a changing number of entries under multiple headings copied
to separate worksheets with the heading name as the worksheet name. I have
almost got it figured out, but need a little help finishing the for loop. I
am having a hard time getting 'startspot' moving over a column (and probably
will have a hard time getting 'startname' to do the same thing). My error is
listed below as the global error which means I'm probably just not
defining/using something properly. One of the "can't see the forest because
of the trees" issues. Any help is much appreciated!

Code as follows:

Dim Numpersonal As Integer, numworkteam As Integer, glcount As Integer


Windows("New Workbook Formatting").Activate
With Worksheets("Printers").Range("B5")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
glcount = Range(.Offset(0, 0), .End(xlToRight)).Columns.Count
End With

Dim startspot As Range, personal As Range, startname As Range

Range("B5").Name = "startspot"
startsheet = 1
Set startname = Range("B5")

For i = 1 To glcount

'Go to correct workbook and select all entries in given column and copy
Windows("New Workbook Formatting").Activate
Sheets("Printers").Range("startspot").Select
With Worksheets("Printers").Range("startspot")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
End With

Set personal = Range("startspot")
personal.Offset(1).Resize(Numpersonal, 1).Select
Selection.Copy

'Paste to new worksheet in CurrentCGAP and rename worksheet
Windows(CurrentCGAP).Activate
Sheets.Add
Range("A8").Select
ActiveSheet.Paste
ActiveSheet.Name = startname

'Move to next column and worksheet
Range(startspot) = Range(startspot).Offset(0, 1) 'error: Method
range of object failed global
Range(startname) = Range(startname).Offset(0, 1)

With ActiveSheet
.Move After:=Worksheets(Worksheets.Count)
End With

Next

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default For Loop with headers

You lost the double quotes around startspot. The double quotes means you
have defined name in your workbook. earlier in the code your have the double
quotes, then latter you forgot to put the double quotes around startspot.

"StumpedAgain" wrote:

I'm trying to get a changing number of entries under multiple headings copied
to separate worksheets with the heading name as the worksheet name. I have
almost got it figured out, but need a little help finishing the for loop. I
am having a hard time getting 'startspot' moving over a column (and probably
will have a hard time getting 'startname' to do the same thing). My error is
listed below as the global error which means I'm probably just not
defining/using something properly. One of the "can't see the forest because
of the trees" issues. Any help is much appreciated!

Code as follows:

Dim Numpersonal As Integer, numworkteam As Integer, glcount As Integer


Windows("New Workbook Formatting").Activate
With Worksheets("Printers").Range("B5")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
glcount = Range(.Offset(0, 0), .End(xlToRight)).Columns.Count
End With

Dim startspot As Range, personal As Range, startname As Range

Range("B5").Name = "startspot"
startsheet = 1
Set startname = Range("B5")

For i = 1 To glcount

'Go to correct workbook and select all entries in given column and copy
Windows("New Workbook Formatting").Activate
Sheets("Printers").Range("startspot").Select
With Worksheets("Printers").Range("startspot")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
End With

Set personal = Range("startspot")
personal.Offset(1).Resize(Numpersonal, 1).Select
Selection.Copy

'Paste to new worksheet in CurrentCGAP and rename worksheet
Windows(CurrentCGAP).Activate
Sheets.Add
Range("A8").Select
ActiveSheet.Paste
ActiveSheet.Name = startname

'Move to next column and worksheet
Range(startspot) = Range(startspot).Offset(0, 1) 'error: Method
range of object failed global
Range(startname) = Range(startname).Offset(0, 1)

With ActiveSheet
.Move After:=Worksheets(Worksheets.Count)
End With

Next

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default For Loop with headers

Even when I put the double quotes back in, I get the same error message. Any
other thoughts? Thanks for the help!

"Joel" wrote:

You lost the double quotes around startspot. The double quotes means you
have defined name in your workbook. earlier in the code your have the double
quotes, then latter you forgot to put the double quotes around startspot.

"StumpedAgain" wrote:

I'm trying to get a changing number of entries under multiple headings copied
to separate worksheets with the heading name as the worksheet name. I have
almost got it figured out, but need a little help finishing the for loop. I
am having a hard time getting 'startspot' moving over a column (and probably
will have a hard time getting 'startname' to do the same thing). My error is
listed below as the global error which means I'm probably just not
defining/using something properly. One of the "can't see the forest because
of the trees" issues. Any help is much appreciated!

Code as follows:

Dim Numpersonal As Integer, numworkteam As Integer, glcount As Integer


Windows("New Workbook Formatting").Activate
With Worksheets("Printers").Range("B5")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
glcount = Range(.Offset(0, 0), .End(xlToRight)).Columns.Count
End With

Dim startspot As Range, personal As Range, startname As Range

Range("B5").Name = "startspot"
startsheet = 1
Set startname = Range("B5")

For i = 1 To glcount

'Go to correct workbook and select all entries in given column and copy
Windows("New Workbook Formatting").Activate
Sheets("Printers").Range("startspot").Select
With Worksheets("Printers").Range("startspot")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
End With

Set personal = Range("startspot")
personal.Offset(1).Resize(Numpersonal, 1).Select
Selection.Copy

'Paste to new worksheet in CurrentCGAP and rename worksheet
Windows(CurrentCGAP).Activate
Sheets.Add
Range("A8").Select
ActiveSheet.Paste
ActiveSheet.Name = startname

'Move to next column and worksheet
Range(startspot) = Range(startspot).Offset(0, 1) 'error: Method
range of object failed global
Range(startname) = Range(startname).Offset(0, 1)

With ActiveSheet
.Move After:=Worksheets(Worksheets.Count)
End With

Next

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default For Loop with headers

I rewrote the FOR loop

For Colcount = 2 To (glcount + 1)


with workbooks(CurrentCGAP)
set newsht = .Sheets.Add(after:=.sheets(.sheets.count)
end with

With workbooks("New Workbook Formatting").Worksheets("Printers")
LastRow = .Cells(6,ColCount).End(xlDown)).Rows

.Range(.cells(5,Colcount),.cells(LastRow,ColCount) ).copy _
destination:=newsht.Range("A8")
Next


"StumpedAgain" wrote:

Even when I put the double quotes back in, I get the same error message. Any
other thoughts? Thanks for the help!

"Joel" wrote:

You lost the double quotes around startspot. The double quotes means you
have defined name in your workbook. earlier in the code your have the double
quotes, then latter you forgot to put the double quotes around startspot.

"StumpedAgain" wrote:

I'm trying to get a changing number of entries under multiple headings copied
to separate worksheets with the heading name as the worksheet name. I have
almost got it figured out, but need a little help finishing the for loop. I
am having a hard time getting 'startspot' moving over a column (and probably
will have a hard time getting 'startname' to do the same thing). My error is
listed below as the global error which means I'm probably just not
defining/using something properly. One of the "can't see the forest because
of the trees" issues. Any help is much appreciated!

Code as follows:

Dim Numpersonal As Integer, numworkteam As Integer, glcount As Integer


Windows("New Workbook Formatting").Activate
With Worksheets("Printers").Range("B5")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
glcount = Range(.Offset(0, 0), .End(xlToRight)).Columns.Count
End With

Dim startspot As Range, personal As Range, startname As Range

Range("B5").Name = "startspot"
startsheet = 1
Set startname = Range("B5")

For i = 1 To glcount

'Go to correct workbook and select all entries in given column and copy
Windows("New Workbook Formatting").Activate
Sheets("Printers").Range("startspot").Select
With Worksheets("Printers").Range("startspot")
Numpersonal = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
End With

Set personal = Range("startspot")
personal.Offset(1).Resize(Numpersonal, 1).Select
Selection.Copy

'Paste to new worksheet in CurrentCGAP and rename worksheet
Windows(CurrentCGAP).Activate
Sheets.Add
Range("A8").Select
ActiveSheet.Paste
ActiveSheet.Name = startname

'Move to next column and worksheet
Range(startspot) = Range(startspot).Offset(0, 1) 'error: Method
range of object failed global
Range(startname) = Range(startname).Offset(0, 1)

With ActiveSheet
.Move After:=Worksheets(Worksheets.Count)
End With

Next

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
lookup using column headers and row headers Memphus01 Excel Discussion (Misc queries) 1 April 13th 09 04:57 PM
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Hide Column Headers but not row (Headers) Kevan Gradwell Excel Programming 1 March 16th 07 05:59 PM
Loop through column headers to search from column name and get cell range Pie Excel Programming 9 December 29th 05 12:17 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM


All times are GMT +1. The time now is 01:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"