Перейти к содержимому

これで完璧!VBAでセルの【罫線】を操作するポイントと便利技

Office TANAKA

0:00 / 0:00

これで完璧!VBAでセルの【罫線】を操作するポイントと便利技

2 179 просмотров · 2 дн. назад
Office TANAKA
96 тыс. подписчиков
2 179 просмотров · 2 дн. назад
マクロでセルに罫線を引くコードを、何も見ないでサッと書けますか?まあ、無理ですよね。私も「え~と...」と考えながら引きますし、ほとんどの方はマクロ記録で調べるのでは?しかし、このマクロ記録が曲者です。たった1つのセルに下線を引いただけなのに、なんとも大量のコードが記録されます。でも、下線を引いて記録されたのだから、意味は分からないけど、これをコピーしちゃえ...という方が多いです。きっと、あなたもその一人でしょう。 罫線の設定って難しいです。いや、難しいと言うよりも"ややこしい"です。単純な"格子状の罫線"や"外枠の罫線"だけなら1行で済むのですが、複数の線種や太さを指定するのなら、罫線の重なりをイメージしなければなりません。そして、本当に難しいのは「どこに罫線を引くか」という、対象セル範囲の特定です。これはもう、罫線とは別の技術が必要になります。 そんな罫線で悩んでいる方に、VBAで罫線を操作するときのポイントと、ほとんど知られていないテクニックをご紹介します。 ------------------------------------------------------------- Can you write VBA code to apply cell borders completely from memory without looking anything up? Almost no one can. I often have to pause and think about it myself, and most users rely on Macro Recorder to inspect the syntax. But Macro Recorder has a major catch: applying a simple bottom underline to just a single cell generates a massive wall of bloated code. Yet because it gets the job done, many people simply copy and paste that recorded code without fully understanding what it does. You have probably done that yourself at least once. Setting up borders programmatically is tricky. It is less about complexity and more about dealing with cumbersome details. While adding a basic grid or outer border only requires a single line of code, combining multiple line styles and weights requires you to visualize how overlapping borders interact. On top of that, the real challenge lies in dynamically identifying the target cell range where borders should be applied—which actually requires a completely separate set of VBA techniques. If you struggle with handling cell borders in VBA, this video covers the essential concepts you need to know, along with several little-known techniques that will make your code far cleaner and easier to manage! 【How to enable English subtitles】 1. Click the "Settings" (gear icon) on the video player. 2. Select "Subtitles/CC". 3. Click "Auto-translate" and choose "English".(Available on PC and mobile app) --- 【Web】 http://officetanaka.net 【セミナー情報】 http://officetanaka.net/seminar/ 【X(旧Twitter)】   / _officetanaka   【Schoo】毎月生放送授業 https://schoo.jp/search?q=田中亨 #excel, #exceltips, #OfficeTANAKA