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 September 26th, 2008, 12:08 PM
Registered User
 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with a Macro

Hi,
I am beginner in VBA.

I wrote macro to split cell content as shown below in Column C in to 3 parts.

Quote:
quote:16700 RR-1, Newmarket, ON L3X 1A1, Canada
105-372 Hollandview Tr, Aurora, ON L4G 0A5, Canada
Code:
Sub splitAddress()

Dim fullAddress, city, address, zipCode As String
Dim stringLength, spaceLoc, thirdCommaLoc As Integer
Dim currRow As Integer
Dim varString As String
Dim i As Integer
Dim j As Integer
Dim intCommaPosition As Variant


For currRow = 1 To 500
    If Len(Trim(ActiveSheet.Cells(currRow, 3).Value)) <> 0 Then
        fullAddress = ActiveSheet.Cells(currRow, 3)
        varString = fullAddress
        intCommaPosition = 0
    For i = 1 To 3
        j = InStr(1, varString, ",")
        If j = 0 Then
            Exit For
        Else
            varString = Right(varString, Len(varString) - j)
        End If
        intCommaPosition = intCommaPosition + j
    Next i

        stringLength = Len(fullAddress)
        spaceLoc = InStr(1, fullAddress, " ")
        thirdCommaLoc = intCommaPosition
        ActiveSheet.Cells(currRow, 6) = Left(fullAddress, spaceLoc - 1)
        ActiveSheet.Cells(currRow, 7) = Mid(fullAddress, spaceLoc + 1, thirdCommaLoc - spaceLoc - 1)
        ActiveSheet.Cells(currRow, 8) = Right(fullAddress, sringLength - thirdCommaLoc - 1)
    End If
Next currRow

End Sub
Now when I tried to run macro it is saying invalid call or argument. Any help to sort this out is greatly appreciated.

Sincerely.
 
Old September 26th, 2008, 02:47 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe you have the cell addresses reversed.

Try changing "Cells(currRow, 3)"
to "Cells(3,currRow)" for all "Cells" references.

If that doesn't work, try using "Range("C" & currRow)" instead.

There are also several places you'll need to add ".Value" to the end of your "Cells(x,y)" references.





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
Macro problem !! samuel2680 Excel VBA 0 December 20th, 2007 05:19 AM
Outlook macro Russ Thompson Beginning VB 6 0 October 20th, 2004 01:02 PM
Macro Help! Jolin VB How-To 0 April 22nd, 2004 08:38 AM
Macro KennethMungwira Access 1 June 13th, 2003 12:00 AM





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