はじめに 皆さんは「Excelのワークシートで正規表現が使えたら良いのに・・・」と思ったことはないでしょうか? ご存知の通り、正規表現を使うと、ワイルドカードなどとは比較にならない柔軟さで、条件に一致する文字列を指定することができるようになります。 この記事では、文字列抽出の条件に正規表現を使用できるユーザ定義関数を作成する方法を紹介します。 設計方針 Excelには、正規表現の関数が無いので、VBAとVBScriptのRegExp関数を組み合わせることで、ユーザ定義関数を作成します。 作成する関数は、ワークシート関数として使いやすいように、以下のような動作で作成しました。 戻り値は1つだけ。 (複数マッチは無視して、最初にマッチした文字列だけを取り扱う。) オプションでサブマッチに対応する。 サブマッチを使用する場合は、正規表現でグループ化をした上で、第三引数にサブマッチのindexを指
今回の記事では、テキストファイルのエンコーディングを、シフト JIS から BOM あり/なしの UTF-8 に変換するバッチプログラムを紹介します。 内容が Excel から少し離れますが、次の記事で CSV ファイルの文字化け問題を取り上げる予定で、それに関連して Windows でのテキストエンコーディングの話題を本記事として切り離し、先行公開するものです。 【本記事のバッチは非推奨です】 改善された最新版の UTF-8 変換バッチを公開しました。 本記事のバッチは非推奨とさせていただきます。 本記事の一部バッチにあった不具合を解消したうえ、信頼性、使い勝手もよくなっていますので、今後はこちらのご利用をよろしくお願いいたします。 www.shegolab.jp 【更新 2018/05/12】 バッチプログラムを一部修正しました。Windows 10 の UTF-8 サポートへの対応で
Excelで扱うことの多い最大値Maxと最小値Minですが、実はVBAには関数が存在しません。そこで、Excelのワークシート関数を用いて、VBAでも最大値と最小値を求める方法をご紹介します。 VBAでMax,Minで最大値や最小値を求める VBA関数も含め、VBAではメソッド・プロパティでもMax, Minというのは存在しません。そこで、Excel-VBAではExcelのワークシート関数Max, Minを「Application.WorksheetFunctionプロパティ」により使用します。例えば、セルB2~H8までのセルに記入された数値の最大値, 最小値を求めるマクロは下記のとおりです。 マクロ例: Sub Max_Min_Sample() Dim maxVal As Long, minVal As Long 'Excelのワークシート関数を使う With Application.W
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く