ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] Error 'Object variable or With block variable not set'

[µo°Ý] Error 'Object variable or With block variable not set'

¥H¤Uµ{§Ç°õ¦æ¨ì¬õ¦â³¡¥÷´N¥X²{error 'Object variable or With block variable not set'¡A­ì¦]¬O¤°»ò¡H

¨Ó¦Ü·L³n©x¤èºô¡Ghttp://msdn.microsoft.com/en-us/library/office/aa195732%28v=office.11%29.aspx
With Worksheets(1).Range("a1:a500")
    Set c = .Find(2, lookin:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Value = 5
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With

¦^´_ 1# zxcxz
  1. Option Explicit
  2. Sub Ex()
  3.     Dim C As Range, firstAddress As String
  4.     With Worksheets(1).Range("a1:a500")
  5.     .Parent.Select
  6.     Set C = .Find(2, LookIn:=xlValues)  '[a1:a500] ·j´M 2
  7.     If Not C Is Nothing Then
  8.         firstAddress = C.Address
  9.         Do
  10.             C.Value = 5  '¤@ª½¦a±N2´«¸m¬°5,³Ì«á¦A¤]¨S2¤F
  11.             Set C = .FindNext(C)
  12.             '·j´M [a1:a500] ¤U¤@­Ó 2
  13.             C.Select  '¨S¦³2®É C Is Nothing '--> C.Address ¿ù»~¨S¦³³]©wÅܼÆ
  14.         Loop While Not C Is Nothing 'And C.Address <> firstAddress
  15.     End If
  16. End With
  17. End Sub
  18. Sub Ex1()
  19.     Dim C As Range, firstAddress As String
  20.     With Worksheets(1).Range("a1:a500")
  21.         Set C = .Find(2, LookIn:=xlValues)  '[a1:a500] ·j´M 2
  22.         If Not C Is Nothing Then
  23.             firstAddress = C.Address   '
  24.             Do
  25.                 '¤£°õ¦æ C.Value = 5
  26.                 Set C = .FindNext(C)        '·j´M [a1:a500] ¤U¤@­Ó 2
  27.                 MsgBox C.Address <> firstAddress
  28.                 '²×·|¦^¨ì²Ä¤@2 -> C.Address = firstAddress  'Â÷¶}°j°é
  29.             Loop While C.Address <> firstAddress  '±ø¥ó¦¨¥ß¤@ª½°õ¦æ°j°é
  30.         End If
  31.     End With
  32. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 1# zxcxz
¥i§ï¦¨³o¼Ë¡A¦]¬°c¬°nothing®ÉµLªk¦A§PÂ_c.address
  1. With Worksheets(1).Range("a1:a500")
  2.     Set c = .Find(2, LookIn:=xlValues)
  3.     If Not c Is Nothing Then
  4.         firstAddress = c.Address
  5.         Do
  6.             c.Value = 5
  7.             Set c = .FindNext(c)
  8.             If c Is Nothing Then Exit Do
  9.         Loop While c.Address <> firstAddress
  10.     End If
  11. End With
½Æ»s¥N½X

TOP

ÁÂÁª©¥D¤Îstillfish00Á¿¸Ñ

TOP

        ÀR«ä¦Û¦b : §g¤l¥ß«í§Ó¡A¤p¤H«í¥ß§Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD