Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Subscript out of range?

The following code takes data from one spreadsheet and transfers it to
another series of workbooks it creates from the list in the source
workbook.

Sub CreateMitigWS()

'Validate worksheets present
Dim wbSourceA As Workbook
Dim wsSourceA As Worksheet
Dim wsSourceB As Worksheet
Dim wsTemplate As Worksheet '(contains macro)
Dim wbCty As Workbook
Dim sCty As String
Dim iCtyRow As Integer

Set wbSourceA = Workbooks("SFY2009 Mitigation Datasource(version1).xls")
'"Subscript out of range"
Set wsSourceA = wbSourceA.Worksheets("CoVR_ModelImportDataBOS")
'set wbsourceB =
'wsSourceA Insert blank columns in cols E, then 2 blank cols at D and E
wsSourceA.Columns("E:E").Insert
wsSourceA.Columns("D:E").Insert

iCtyRow = 3

Do
sCty = wsSourceA.Range("A" & iCtyRow)
Set wbCty = Workbooks.Add '(workbook created for each county)
wbCty.SaveAs Filename:=sCty & " Mitigation Data SFY2009"
ThisWorkbook.Worksheets("Source").Range("A1:F33"). Copy
Destination:=wbCty.ActiveSheet.Range("A1")
wsSourceA.Range("B" & iCtyRow & ":N" & iCtyRow).Copy
wbCty.Worksheets("Sheet1").Range("B5").PasteSpecia l Paste:=xlPasteValues,
_
Operation:=xlNone, SkipBlanks:=False, Transpose:=True
wbCty.Worksheets("Sheet1").Range("A1").Value = "County Name: " & sCty
'Reformat the col A width and all row heigths
Columns("A:A").ColumnWidth = 36.57
Cells.Select
Cells.EntireRow.AutoFit

iCtyRow = iCtyRow + 1
Loop Until sCty = "Baca"

iCtyRow = iCtyRow - 3
MsgBox "You have created " & iCtyRow & " files!", vbOKOnly

End Sub

This code ran fine until I moved the worksheet with the code and the other
worksheet to a different directory on a different drive. So they are both
still in the same folder, but a different one from where they were created.
I thought that as long as they were in the same folder, they'd work.
Apparently not. Any ideas on how to get them to?

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Subscript out of range?

On Wed, 13 May 2009 10:45:43 -0600, salgud wrote:

The following code takes data from one spreadsheet and transfers it to
another series of workbooks it creates from the list in the source
workbook.

Sub CreateMitigWS()

'Validate worksheets present
Dim wbSourceA As Workbook
Dim wsSourceA As Worksheet
Dim wsSourceB As Worksheet
Dim wsTemplate As Worksheet '(contains macro)
Dim wbCty As Workbook
Dim sCty As String
Dim iCtyRow As Integer

Set wbSourceA = Workbooks("SFY2009 Mitigation Datasource(version1).xls")
'"Subscript out of range"
Set wsSourceA = wbSourceA.Worksheets("CoVR_ModelImportDataBOS")
'set wbsourceB =
'wsSourceA Insert blank columns in cols E, then 2 blank cols at D and E
wsSourceA.Columns("E:E").Insert
wsSourceA.Columns("D:E").Insert

iCtyRow = 3

Do
sCty = wsSourceA.Range("A" & iCtyRow)
Set wbCty = Workbooks.Add '(workbook created for each county)
wbCty.SaveAs Filename:=sCty & " Mitigation Data SFY2009"
ThisWorkbook.Worksheets("Source").Range("A1:F33"). Copy
Destination:=wbCty.ActiveSheet.Range("A1")
wsSourceA.Range("B" & iCtyRow & ":N" & iCtyRow).Copy
wbCty.Worksheets("Sheet1").Range("B5").PasteSpecia l Paste:=xlPasteValues,
_
Operation:=xlNone, SkipBlanks:=False, Transpose:=True
wbCty.Worksheets("Sheet1").Range("A1").Value = "County Name: " & sCty
'Reformat the col A width and all row heigths
Columns("A:A").ColumnWidth = 36.57
Cells.Select
Cells.EntireRow.AutoFit

iCtyRow = iCtyRow + 1
Loop Until sCty = "Baca"

iCtyRow = iCtyRow - 3
MsgBox "You have created " & iCtyRow & " files!", vbOKOnly

End Sub

This code ran fine until I moved the worksheet with the code and the other
worksheet to a different directory on a different drive. So they are both
still in the same folder, but a different one from where they were created.
I thought that as long as they were in the same folder, they'd work.
Apparently not. Any ideas on how to get them to?

TIA


Nevermind! Found a missing space in the filename. Paniced a bit, got to
have this done by the end of the day.
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
subscript out of range [email protected] Excel Programming 5 February 19th 07 08:28 PM
Subscript out of range Greg Glynn Excel Programming 3 October 11th 06 10:43 PM
Subscript out of range z00h Excel Programming 5 March 7th 06 04:08 PM
Subscript out of range? Jason Hancock Excel Programming 3 May 26th 04 07:11 PM
SubScript Out Of Range. Sam Excel Programming 4 December 21st 03 02:10 AM


All times are GMT +1. The time now is 09:38 AM.

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"