+ Reply to Thread
Results 1 to 3 of 3

Changing Ranges in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2005
    Posts
    46

    Question Changing Ranges in VBA

    Dear all,

    I have written the following code which replaces "" (a blank) with a zero, yet it applies to the whole workbook. How would I change this to apply it to the active sheet of range A1 to J815209?

    Sub ReplaceCharacter()
    For Each mySheet In ThisWorkbook.Worksheets
    mySheet.Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Next
    End Sub
    Thanks
    smurray444

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try

    Sheet1.Range("A1:J815209").Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to change your code:
    Sub ReplaceCharacter()
       lastrow = cells(rows.count,"j").end(xlup).row
       activeSheet.range("a1:j" & lastrow).Replace What:="", Replacement:=0, LookAt:=xlPart,     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,   ReplaceFormat:=False
    End Sub
    Regards,
    Antonio

+ 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