+ Reply to Thread
Results 1 to 6 of 6

Macro to replace text in column and transfer

Hybrid View

undergraduate Macro to replace text in... 01-11-2011, 10:13 PM
stanleydgromjr Re: Macro to replace text in... 01-12-2011, 12:16 AM
undergraduate Re: Macro to replace text in... 01-12-2011, 10:53 AM
undergraduate Re: Macro to replace text in... 01-12-2011, 11:20 AM
stanleydgromjr Re: Macro to replace text in... 01-12-2011, 08:28 PM
undergraduate Re: Macro to replace text in... 01-12-2011, 08:39 PM
  1. #1
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Macro to replace text in column and transfer

    Hi, so I was able to fix that aspect of the above code. Thank You. It runs on all worksheets
    However I keep getting a runtime error 91 : Object variable or with block variable not set
    Wondering how best to fix this

    Sub asda()
    
    Dim q As Integer
    Dim currentsheet As Worksheet
    Dim c As Range, firstaddress As String, a As Long
    Worksheets(1).Activate
    
    For q = 1 To ActiveWorkbook.Worksheets.Count
    Set currentsheet = ActiveWorkbook.Worksheets(q)
    Worksheets(q).Activate
    
    
    With Columns(1)
      Set c = .Find("Investor", LookIn:=xlValues, LookAt:=xlWhole)
      If Not c Is Nothing Then
        firstaddress = c.Address
        Do
          a = a + 1
          If a > 1 Then c = "Holder"
          c.Offset(, 3) = "% of CSO"
          Range("C" & c.Row & ":C" & c.Row + 20).Value = Range("D" & c.Row & ":D" & c.Row + 20).Value
          Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstaddress
        Range(firstaddress) = "Holder"
        
      End If
    End With
    
    Next q
    
    End Sub
    Last edited by undergraduate; 01-12-2011 at 12:07 PM. Reason: Object variable or with block variable not set

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to replace text in column and transfer

    undergraduate,

    Try:

    
    Option Explicit
    Sub asda()
    Dim q As Integer
    Dim currentsheet As Worksheet
    Dim c As Range, firstaddress As String, a As Long
    Worksheets(1).Activate
    For q = 1 To ActiveWorkbook.Worksheets.Count
    Set currentsheet = ActiveWorkbook.Worksheets(q)
    Worksheets(q).Activate
      firstaddress = ""
      With Columns(1)
        Set c = .Find("Investor", LookIn:=xlValues, LookAt:=xlWhole)
        If Not c Is Nothing Then
          firstaddress = c.Address
          Do
            a = a + 1
            If a > 1 Then c = "Holder"
            c.Offset(, 3) = "% of CSO"
            Range("C" & c.Row & ":C" & c.Row + 20).Value = Range("D" & c.Row & ":D" & c.Row + 20).Value
            Set c = .FindNext(c)
          Loop While Not c Is Nothing And c.Address <> firstaddress
          Range(firstaddress) = "Holder"
        End If
      End With
    Next q
    End Sub
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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