[[20040713112113]] 『アルファベットのみ削除したいのですが 』(わからず) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『アルファベットのみ削除したいのですが 』(わからず)

いつも参考にさせていただいています。つまずいた(わからない)個所ありますので
良いアドバイスお願いします。
セルにA1-A10とある場合表記をA1-10と10の前のアルファベットを削除したい場合どうしたら
良いでしょうか?
セルにはABC1-ABC10等もありこの表記もABC1-10とさせたいです。
どなたか良いアドバイスお願いしますm(_ _)m


 >A1-A10とある場合表記をA1-10
 -?  → - に「置換」

 >セルにはABC1-ABC10等もありこの表記もABC1-10
 -???  → - に「置換」

  (INA)

INAさん さっそくのご回答ありがとうございます。
A列に
A1-A10
AA1-AA10
AAA1-AAA10
とある場合順に変換をかけていくと最初のA1-A10がA1-だけとなってしまいます。
なんとか一括で-後のアルファベットのみを削除する方法はないでしょうか?
(わからず)

 数式で削除するものでは、当該セルがA1だとしますと、
 =IF(COUNTIF(A1,"*-*"),
 LEFT(A1,FIND("-",A1))&LOOKUP(99^9,--RIGHT(A1,COLUMN(1:1))),"")
 というものは、どうでしょう?                   (LOOKUP)

LOOKUPさん回答ありがとうございます。さっそくためさせてもらった所ばっちりできました。
数式を貼り付けていた所、あらたな記述がでてきました。
A1-A10,A12,A15,A17-A20 とある場合、上記の数式ではA1-20と表示されますよね?
A1-10,12,15,17-20と頭のAのみ残す数式はありますでしょうか?
VBAのコードで教えてもらえるとありがたいのですが・・・(わからず)

 マクロの記録で作成しました。                (LOOKUP)
Sub Macro1()
Dim MAE As String
Dim ATO As String
Dim R As Range
Dim I As Integer
For Each R In Selection
If Application.CountIf(R, "*-*") = 0 Then Exit For
I = Application.Find("-", R.Value)
MAE = Left(R.Value, I)
ATO = Application.Substitute(R.Value, MAE, "", 1)
ATO = Application.Substitute(ATO, "A", "")
ATO = Application.Substitute(ATO, "B", "")
ATO = Application.Substitute(ATO, "C", "")
ATO = Application.Substitute(ATO, "D", "")
ATO = Application.Substitute(ATO, "E", "")
ATO = Application.Substitute(ATO, "F", "")
ATO = Application.Substitute(ATO, "G", "")
ATO = Application.Substitute(ATO, "H", "")
ATO = Application.Substitute(ATO, "I", "")
ATO = Application.Substitute(ATO, "J", "")
ATO = Application.Substitute(ATO, "K", "")
ATO = Application.Substitute(ATO, "L", "")
ATO = Application.Substitute(ATO, "M", "")
ATO = Application.Substitute(ATO, "N", "")
ATO = Application.Substitute(ATO, "O", "")
ATO = Application.Substitute(ATO, "P", "")
ATO = Application.Substitute(ATO, "Q", "")
ATO = Application.Substitute(ATO, "R", "")
ATO = Application.Substitute(ATO, "S", "")
ATO = Application.Substitute(ATO, "T", "")
ATO = Application.Substitute(ATO, "U", "")
ATO = Application.Substitute(ATO, "V", "")
ATO = Application.Substitute(ATO, "W", "")
ATO = Application.Substitute(ATO, "X", "")
ATO = Application.Substitute(ATO, "Y", "")
ATO = Application.Substitute(ATO, "Z", "")
R.Value = MAE & ATO
Next R
End Sub

LOOKUPさん 何度もありがとうございます。
説明不足で申し訳ないです。記述にはA1,A3-5,A7とある場合、上記コードを
実行するとA1,A3-5,7となってしまいます。A1,3-5,7のように先頭行のみ
アルファベットがつくようにしたいのですが・・・大変お手数をかけますがお願いします。
(わからず)

 -のところで区切るのでは、ないのですね。これは、どうでしょう?  (LOOKUP)
Sub Macro1()
Dim MAE As String
Dim ATO As String
Dim R As Range
Dim I As Integer
For Each R In Selection
If Len(R.Value) = 0 Then GoTo MUSI
I = 1
Do Until Asc(Mid(R.Value, I, 1)) > 90 _
Or Asc(Mid(R.Value, I, 1)) < 65 _
Or I = Len(R.Value)
I = I + 1
Loop
MAE = Left(R.Value, I)
ATO = Application.Substitute(R.Value, MAE, "", 1)
ATO = Application.Substitute(ATO, "A", "")
ATO = Application.Substitute(ATO, "B", "")
ATO = Application.Substitute(ATO, "C", "")
ATO = Application.Substitute(ATO, "D", "")
ATO = Application.Substitute(ATO, "E", "")
ATO = Application.Substitute(ATO, "F", "")
ATO = Application.Substitute(ATO, "G", "")
ATO = Application.Substitute(ATO, "H", "")
ATO = Application.Substitute(ATO, "I", "")
ATO = Application.Substitute(ATO, "J", "")
ATO = Application.Substitute(ATO, "K", "")
ATO = Application.Substitute(ATO, "L", "")
ATO = Application.Substitute(ATO, "M", "")
ATO = Application.Substitute(ATO, "N", "")
ATO = Application.Substitute(ATO, "O", "")
ATO = Application.Substitute(ATO, "P", "")
ATO = Application.Substitute(ATO, "Q", "")
ATO = Application.Substitute(ATO, "R", "")
ATO = Application.Substitute(ATO, "S", "")
ATO = Application.Substitute(ATO, "T", "")
ATO = Application.Substitute(ATO, "U", "")
ATO = Application.Substitute(ATO, "V", "")
ATO = Application.Substitute(ATO, "W", "")
ATO = Application.Substitute(ATO, "X", "")
ATO = Application.Substitute(ATO, "Y", "")
ATO = Application.Substitute(ATO, "Z", "")
R.Value = MAE & ATO
MUSI:
Next R
End Sub

LOOKUPさんありがとうございます。出来ました(^0^)ありがとうございます。

 最後まで、ご希望が判らなかったです。
 もしも、ご質問が、下のように共通の英字を最初だけ表示させることでしたら、
 英字が10文字以内としまして、配列数式ですが、

 =IF(LEN(A1)>1,LEFT(A1,MATCH(1,MID(A1,ROW($2:$10),1)^0,))
 &SUBSTITUTE(A1,LEFT(A1,MATCH(1,MID(A1,ROW($2:$10),1)^0,)),),"")
 として、Ctrl+Shift+Enter。でも変換できると思います。           (LOOKUP)

   A                  B
1 ABC5-10,ABC12,ABC13-ABC17,ABC21 ABC5-10,12,13-17,21
2 LM23,LM25,LM27-LM29,LM31     LM23,25,27-29,31

コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.