準・究極の選択

エクセルのマクロでhttpが入っている列を削除するマクロを組みたいのですがどうすれば良いですか?

A 回答 (3件)

こんにちは!



No.1さんが回答されている方法そのままです。

Sub Sample1()
 Dim FoundCell As Range, FirstCell As Range
 Dim myRng As Range

 With ActiveSheet
  Set FoundCell = .Cells.Find(what:="http", LookIn:=xlValues, lookat:=xlPart)
   If Not FoundCell Is Nothing Then
    Set FirstCell = FoundCell
    Set myRng = FoundCell
     Do
      Set FoundCell = .Cells.FindNext(after:=FoundCell)
       If FoundCell.Address = FirstCell.Address Then Exit Do
       Set myRng = Union(myRng, FoundCell)
     Loop
      If Not myRng Is Nothing Then
       myRng.EntireColumn.Select '//★//
      End If
   End If
 End With
End Sub

※ 列選択でやめています。
間違いがなければ「★」の行を
>myRng.EntireColumn.Delete

に変更してください。m(_ _)m
    • good
    • 0

No1です



>できませんでした
「何もしていない」から「あと一歩のところ」まで、ピンキリの意味が考えられるので、反応のしようがありません。

コピペできるものが欲しいのなら、すでにNo2様が回答なさってくださっています。
とりあえず、No1の回答の意味するままを示しておくなら(必要最低限)

Sub Sample()
 Dim r As Range
 Set r = Cells.Find(What:="http", LookIn:=xlValues, LookAt:=xlPart)
 Do While Not r Is Nothing
  r.EntireColumn.Delete
  Set r = Cells.FindNext()
 Loop
End Sub
    • good
    • 0

こんにちは



>どうすれば良いですか?
検索して、該当するセルの列を削除すれば宜しいかと。

検索方法にもいろいろあると思いますが、例えば、Findを用いるなら
 Set r = Cells.Find(What:="http", LookIn:=xlValues, LookAt:=xlPart)
みたいな感じで、見つからなくなるまでループすれば宜しいかと。

Findメソッドの使い方や説明は以下をご参照ください。
https://docs.microsoft.com/ja-jp/office/vba/api/ …
    • good
    • 0
この回答へのお礼

できませんでした

お礼日時:2019/05/31 10:41

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!