Syntax for range (column) in vbs

PW1202

New Member
Joined
Apr 19, 2018
Messages
1
My code so far is:
Rich (BB code):
Option Explicit

Private Sub Worksheet_Calculate()

Dim Rng1            As Range
Dim Value           As Double
Dim Prompt          As String
Dim Title           As String

    'Put the range you want to test here
    Set Rng1 = Range("T14")
    
    'Put the target value here
    Value = "1"

    'Put the message (prompt) of the message box (pop up) here
    Prompt = "Sub group must be part of the Group"

    'Put the title of the message box (pop up) here
    Title = "Group/ Sub Group mismatch"

    If Rng1.Value = Value Then
            MsgBox Prompt, vbInformation, Title
    End If

End Sub

and it works well when the range is "T14", but I want to module to check any (all) cells in column T. I have tried "$T" and other variations, but they all fail. Need the syntax for column T as the range.


Would appreciate any help.

Peter.
 
Last edited by a moderator:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi & welcome to the board.
How about
Code:
Private Sub Worksheet_Calculate()

Dim Cl              As Range
Dim Value           As Double
Dim Prompt          As String
Dim Title           As String

    
    'Put the target value here
    Value = "1"

    'Put the message (prompt) of the message box (pop up) here
    Prompt = "Sub group must be part of the Group"

    'Put the title of the message box (pop up) here
    Title = "Group/ Sub Group mismatch"

    For Each Cl In Range("T1", Range("T" & Rows.Count).End(xlUp))
      If Cl.Value = Value Then
         MsgBox Prompt, vbInformation, Title
         Exit For
      End If
   Next Cl

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top