Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2007, 09:08 AM
Registered User
 
Join Date: Oct 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copying files error

I am trying to scan through some data and copy certain lines over to a new work book. I got it working but it doesn't seem to be working correctly 100%

It is suppose to scan through column 1 and recognize a ";" and the number "25" as the first character(s), and if it finds one, copy each row containing those characters to a seperate workbook.

It does just that, but it seems to copy the same row every time it finds a semicolon or a 25.

here is the code i have:

Sub PnP_Column1_FindSemiColon()

Dim oWB1 As Workbook ' input worksheet
Dim oWB2 As Workbook ' output worksheet

Dim bRet As Boolean
Dim cRet As Boolean

Set oWB1 = ActiveWorkbook
Set oWB2 = Workbooks.Add

Dim i1 As Long
Dim i2 As Long

Dim arSemiColonAdd() As String
Dim arFindNo25Add() As String
Dim iRow

bRet = FindAll(";", oWB1.Sheets(1), "A:A", arSemiColonAdd)
cRet = FindAll("25", oWB1.Sheets(1), "A:A", arFindNo25Add)

i2 = 1
    If bRet = True Then

        For i1 = 1 To UBound(arSemiColonAdd)
            i2 = i2 + 1
            iRow = Right(arSemiColonAdd(i1), Len(arSemiColonAdd(i1)) - InStrRev(arSemiColonAdd(i1), "$"))
            oWB1.Sheets(1).Rows(iRow).EntireRow.Copy Destination:=oWB2.Sheets(1).Range("A" & i2)
        Next i1

    End If

    If cRet = True Then

        For il = 1 To UBound(arFindNo25Add)
            i2 = i2 + 1
            iRow = Right(arFindNo25Add(i1), Len(arFindNo25Add(i1)) - InStrRev(arFindNo25Add(i1), "$"))
            oWB1.Sheets(1).Rows(iRow).EntireRow.Copy Destination:=oWB2.Sheets(1).Range("A" & i2)
        Next il
    

    End If
End Sub

The FindAll function is a function of a member here on the boards, and it seems to be doing its job, just it just seems to duplicate the rows it finds when they should all be somewhat different.

as in:


25 1 270 0.45 1.527 J1 WM7676
25 1 90 1.8 0.974 J2 WM7676
25 1 270 2.7 1.527 J3 WM7676
25 1 90 4.05 0.974 J4 WM7676
25 1 270 4.95 1.527 J5 WM7676
25 1 90 6.3 0.974 J6 WM7676
25 1 270 7.2 1.527 J7 WM7676
25 1 90 8.55 0.974 J8 WM7676 <--copies this row only for some reason

but instead i get:

25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676
25 1 90 8.55 0.974 J8 WM7676


can anyone see the problem??

Thanks
 
Old November 10th, 2007, 10:11 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You have almost made it Kwick

Just replace

 For il = 1 To UBound(arFindNo25Add)

with

 For i1 = 1 To UBound(arFindNo25Add)

(Variables il and i1 looks alike isn't it):)

I think an Option Explicit at the start of the code would have saved your time


Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on Uploading files regali PHP How-To 0 December 3rd, 2006 02:37 PM
Copying data across files sda443 Excel VBA 2 January 16th, 2006 06:49 AM
Copying selected files in vb sunitha_padmanabhan VB Components 2 November 15th, 2004 07:43 AM
Copying files using VBScript in ADO 3.0 munrrob Classic ASP Basics 2 October 26th, 2004 05:35 AM
Copying files marclena General .NET 2 June 18th, 2004 08:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.