Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2016, 09:20 PM
H28Sailor H28Sailor is offline VBA Routine debug question Windows 7 32bit VBA Routine debug question Office 2007
Advanced Beginner
VBA Routine debug question
 
Join Date: Mar 2013
Posts: 55
H28Sailor is on a distinguished road
Default VBA Routine debug question

I have the following code:-

Sub CopyRows()
' copy all rows of data in worksheet 'temp' to the appropriate worksheets
Dim iLooper As Long, NextRow As Long, ws As Worksheet, strSheet As String
With Worksheets("temp")
For iLooper = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
If UCase(Trim(.Cells(iLooper, "B").Value)) Like "ENROLLMENT*" Then
strSheet = "ENROLLMENT"
ElseIf UCase(Trim(.Cells(iLooper, "B").Value)) Like "WEEK*" Then
strSheet = .Cells(iLooper, "a").Text
Else
strSheet = ""
End If
If strSheet <> "" Then
Set ws = Worksheets(strSheet)
NextRow = ws.Columns("B").Find("*", , xlValues, , 1, 2).Row + 1
ws.Rows(NextRow).Insert
ws.Cells(NextRow, "A").Resize(, 8).Value = _
.Cells(iLooper, "A").Resize(, 8).Value
End If
Next
End With
' delete all rows of data in worksheet 'temp'
Dim r As Long
For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(r, 1) = "" Then Rows(r).Delete
Next r
End Sub

When run I get a run-time error '9': Subscript out of range together with the bold, italic line above highlighted



The routine processes all the lines as they should be - and so the error occurs at the end of processing and, of course, the lines of data in 'temp' are not erased

Would welcome any comments on how to correct the code..........

Bob M
Reply With Quote
  #2  
Old 12-05-2016, 10:51 PM
macropod's Avatar
macropod macropod is offline VBA Routine debug question Windows 7 64bit VBA Routine debug question Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Duplicate of: https://www.msofficeforums.com/excel...-question.html

Thread closed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Routine debug question Debug error gbaker Excel Programming 5 10-01-2016 10:35 AM
VBA Routine debug question automated form filling routine / process Smithy02468 Excel Programming 1 11-08-2014 11:29 PM
VBA Routine debug question How to create an error debug message shilabrow Excel Programming 1 06-27-2014 07:30 PM
VBA Routine debug question Data got getting returned from Sub Routine Hwyn Excel Programming 5 01-18-2012 08:02 AM
Macro or routine required evanhughes Outlook 0 11-18-2011 02:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft