SSブログ

設定した名前つきセルだけ選択(入力)できるようにする実験 Excel2000 VBA [Excel2000 VBA独習]

設定した名前つきセルだけ選択(入力)できるようにする実験

入力(選択)出来るようにしたいセル(範囲)に「入力」 と名前の設定をする。
名前の設定方法は、挿入→名前→定義から設定する。

下記のコードをシートのコード欄に記述

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   On Error Resume Next
   Dim scope As Range
   Dim today_row As Long
'名前つきセルの範囲を設定
   Set scope = Range("入力")
  
'選択セル判定
   With Application
      If .Intersect(Target, scope) Is Nothing _
      Then
         .EnableEvents = False
         .PreviousSelections(1).Select
         .EnableEvents = True
      Else
         .Goto ActiveCell
      End If
   End With
'数式セルは選択出来ないようにする(数式ならば右移動)
'If Target.HasFormula = True Then Target.Offset(0, 1).Select
'セットの解除
   Set scope = Nothing

End Sub

 


選択範囲に「入力」の名前をつける。(選択可能にする)

 

Sub 選択セル範囲に名前を付ける()
'

On Error GoTo owari
Dim hani As Range
Dim inC As String

'ワークシートイベントを無効にする
    Application.EnableEvents = False
'範囲取得
    inC = "名前を付ける範囲を指定(名前「入力」)" & vbLf + vbLf & "Ctrlキーを押しながら複数の範囲指定も可" _
    & vbLf + vbLf & "注意 現在設定されている名前は無効になります。"
    Set hani = Application.InputBox(inC, Type:=8)
   
'選択範囲に名前をつける。名前は「入力」
    hani.Name = "入力"
    hani.Interior.ColorIndex = 6 '名前をつけた範囲を分かりやすくする為色を設定
   
'ワークシートイベントを有効にする
    Application.EnableEvents = True
owari:
Set hani = Nothing
End Sub


Sub 選択セル範囲に名前を付ける()
'ワークシートイベントを無効してから実行
'ワークシートイベントを無効にする
    Application.EnableEvents = False
'選択範囲に名前をつける。名前は「入力」
    Selection.Name = "入力"
    'Selection.Interior.ColorIndex = 6 '名前をつけた範囲を分かりやすくする為色を設定
'ワークシートイベントを有効にする
    Application.EnableEvents = True
End Sub


Sub シートイベント有効無効()
If Application.EnableEvents = False Then Application.EnableEvents = True Else Application.EnableEvents = False
End Sub



 


タグ:Excel2000 VBA
nice!(0)  コメント(9)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 9

Smithe837

I've been absent for a while, but now I remember why I used to love this site. Thank you, I'll try and check back more frequently. How frequently you update your site? gacgekedafbdaacd
by Smithe837 (2014-05-23 18:29) 

Pharma149

Very nice site! <a href="http://oixypea2.com/oxovqor/1.html">cheap goods</a>
by Pharma149 (2014-05-24 09:18) 

Pharmg499

Very nice site! <a href="http://opeaixy2.com/qsqsrqa/1.html">cheap goods</a>
by Pharmg499 (2014-05-24 13:37) 

Pharmd745

Very nice site! [url=http://opeaixy2.com/qsqsrqa/2.html]cheap goods[/url]
by Pharmd745 (2014-05-24 13:39) 

Smitha641

certainly like your website however you have to check the spelling on several of your posts. Many of them are rife with spelling problems and I to find it very troublesome to inform the truth nevertheless I will surely come back again. fdfdadeadagbcced
by Smitha641 (2014-06-21 06:36) 

Smithd73

That alone wwas an egregious oversight on thheir own part, since fbdaebkekeedddkg
by Smithd73 (2014-06-22 23:18) 

cia_lis

I keep listening to the news update lecture about receiving boundless online grant applications so I have been looking around for the top site to get one. Could you advise me please, where could i acquire some?
by cia_lis (2014-10-26 09:35) 

dosage

I conceive you have remarked some very interesting points , regards for the post.
by dosage (2015-06-11 13:36) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。