
困っています。どなたか教えてください。
下記のように作成しましたが、
A列に文字が入っていたら、上下に線を引くというプロシージャにしたいと思っています。
If Cells(c, 4) = "" Then
Range(Cells(c, 1), Cells(c, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
bolFlg = True
Else
まだまだ続きますが・・・・。
よろしくお願いいたします。
No.1ベストアンサー
- 回答日時:
>まだまだ続きますが・・・・。
どこが不明なのでしょう?
いずれにしても
>If Cells(c, 4) = "" Then
では、Cells(c, 1)にしないとA列にはなりませんよね?
文字が入っていたらと言う条件なら、Cells(c, 1) <> "" とします。
この回答への補足
早速のご回答ありがとうございます。
空白でも、文字が入っていても線を引けてしまいます。A列に文字が入ったら線を引くにしたいのです。
全文表示します。
Dim bolFlg As Boolean
Dim intCount As Integer
Range("a1").Select
ActiveCell.CurrentRegion.BorderAround xlContinuous, xlThin
最下行 = Range("a1").CurrentRegion.Rows.Count
'最下列 = Range("a1").CurrentRegion.Column.Count
bolFlg = True: intCount = 0
For c = 1 To 最下行 - 1
intCount = intCount + 1
If Cells(c, 4) = "" Then
Range(Cells(c, 1), Cells(c, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
bolFlg = True
Else
If bolFlg = True Then
Range(Cells(c, 1), Cells(c, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Else
Range(Cells(c, 1), Cells(c, 6)).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
bolFlg = False
If Cells(c, 4) = "数量" Then
bolFlg = True
End If
If c <= 56 Then
If intCount = 55 Then
Range(Cells(c + 1, 1), Cells(c + 1, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
intCount = 0
End If
Else
If intCount = 56 Then
Range(Cells(c + 1, 1), Cells(c + 1, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
intCount = 0
End If
End If
End If
ActiveCell.Offset(1, 0).Select
Next c
Range(Cells(56, 1), Cells(56, 6)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
No.2
- 回答日時:
最初に、
c = ActiveCell.Row
を入れれば、特に、書かれている限りは、問題はないと思いますが、プロシージャと書きながら、途中を抜き出したものですし、説明もほとんどないので、正確な解答はできないと思います。
例えば、
bolFlg = True
なぜ、フラグを取っているのか、理由が見えてきません。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- Visual Basic(VBA) VBA 罫線について B列3行目から21行毎にデータがはいります。 データがはいったらデータが入った 6 2022/11/15 17:22
- Visual Basic(VBA) エクセルVBA ダブルクリックしたら色反転を指定したセルのみにしたい 2 2022/04/06 12:52
- Excel(エクセル) 日付で矢印マクロ 4 2023/07/25 16:47
- Visual Basic(VBA) ExcelVBAのマクロについて。 9 2022/05/04 14:50
- Visual Basic(VBA) ローマ字、ハイフン付きの並び替え ローマ字抽出方法 Excelマクロ 4 2022/04/01 14:10
- Visual Basic(VBA) ExcelVBAでDo Until loopのネスト、IF文を使って一致する物と一致しない物としたい 11 2022/12/24 17:46
- Visual Basic(VBA) エラーコード1004 6 2022/06/09 14:12
- Visual Basic(VBA) VBA シート上にドロップダウンリストを作り、予め指定値をセットしたいのですが 1 2023/03/25 15:15
- Visual Basic(VBA) 最終列の右へSUM関数を作成するため下記コードを実行しましたが、最終列「10月28日」が上書きされて 3 2022/12/05 20:32
- Visual Basic(VBA) Sheet3から2つの条件でオートフィルターで抽出した個数をSheet2へ入力するマクロで、一つ目の 4 2023/01/12 23:40
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Accessのマクロでモジュールを...
-
Accessのページヘッターを最初...
-
ExcelVBAのInputBoxメソッドの...
-
エクセルのマクロの止め方
-
RTHDCPL.EXE... が起動時に出て...
-
Access VBAで行ラベルが定義さ...
-
【Excel VBA】 WorksheetやRa...
-
エクセルVBAでUserFormを起動し...
-
アクセス enterで次ページ(レ...
-
Accessのプロシージャ名が勝手...
-
callで順に実行されるプロシー...
-
エクセルVBAが対応できるプログ...
-
VBAにおける Option Explicitの...
-
Excel VBAで「プログラム実行」...
-
このページ、どうなってるので...
-
SQL文(クエリ)をご教授くださ...
-
ACCESSのVBAについて
-
ドメインの取得日を変更する方法
-
クエリー
-
日付の表示について
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Accessのマクロでモジュールを...
-
Access VBAで行ラベルが定義さ...
-
エクセルVBAでUserFormを起動し...
-
callで順に実行されるプロシー...
-
Excel VBAで「プログラム実行」...
-
【Excel VBA】 WorksheetやRa...
-
OutlookVBAで作成したマクロに...
-
Accessでグローバル変数を宣言...
-
或るプロシージャの呼び出し元判定
-
VBA プロシージャの名前の取得
-
DBMS_OUTPUT.PUT_LINEを実行し...
-
excel/vba/public変数
-
ACCESS2007インポート時の空白...
-
PL/SQLのエラーについて
-
ACCESS マクロをモジュールに変...
-
エクセルVBAが対応できるプログ...
-
DB2でのストアドプロシージャの...
-
エクセルVBAの次のコードの...
-
Excel:ThisWorkbookオブジェク...
-
アクセスのVBについて
おすすめ情報