+ Reply to Thread
Results 1 to 4 of 4

VBA Code vs Macro Recording code

  1. #1
    Registered User
    Join Date
    04-09-2007
    Posts
    5

    VBA Code vs Macro Recording code

    Hi all, I have an excel spreadsheet that I would like to check for "," and replace with " ". I used a macro recording to get the code but when I enter this code with the rest of my VBA coding it does not work. The code does not come back in error it just steps through each line without making the changes I require. Below is the code

    'Replace all commas with blanks in the text field.
    With Sheets("Form")
    Please Login or Register  to view this content.

    If anyone could come back with some suggests as to why this does not work then hat would help me out a great deal.

    Many thanks

    J
    Last edited by VBA Noob; 04-09-2007 at 06:24 AM.

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by JoeSharp
    Hi all, I have an excel spreadsheet that I would like to check for "," and replace with " ". I used a macro recording to get the code but when I enter this code with the rest of my VBA coding it does not work. The code does not come back in error it just steps through each line without making the changes I require. Below is the code
    Please Login or Register  to view this content.
    If anyone could come back with some suggests as to why this does not work then hat would help me out a great deal.

    Many thanks

    J
    Hi,

    code
    Please Login or Register  to view this content.
    works ok - did you test the range correctly?

    shouldn't 'With Sheets' use .Range?

    ---
    Last edited by Bryan Hessey; 04-09-2007 at 05:24 AM.
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello JoeSharp,

    You made a common syntax error when using the "With ... End With" construct. You didn't precede the properties with a period. Have a look at the amended code...

    Please Login or Register  to view this content.
    The other problem is for this code to run "Forms" needs to be the Active sheet. I added the statement to do this in the code above. Here is a different approach to make the changes without having the Forms sheet Active.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    04-09-2007
    Posts
    5

    Thumbs up Spot on!!

    Thanks!

    It worked!!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1