+ Reply to Thread
Results 1 to 2 of 2

VBA - cell referencing

Hybrid View

  1. #1
    Registered User
    Join Date
    02-25-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    3

    Exclamation VBA - cell referencing

    Basicly what i have is a cell on my worksheet that i want to be able to type another cells address into (aka typing B3 into A1, say B3 has the number 7 in it) and then use a bit of VBA code to make a button to refer to A1 thus B3 thus 7 then add 1 to it then drop it back into B3 making B3=8 and A1=B3 eg;

    Before the button was pressed;

    .....A......B.....C
    1...B3
    2
    3............7
    4

    After the button was pressed;

    .....A......B.....C
    1...B3
    2
    3............8
    4


    Note that the contense of A1 will be ever changing to different cells

    Hope this is possible, cheers for any help.
    Last edited by kwinza; 06-24-2010 at 07:01 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: VBA - cell referencing

    Try

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1"     '<== change to suit
    
        On Error GoTo ws_exit
        Application.EnableEvents = False
    
        If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
            With Target
                Me.Range(.Value2).Value2 = Me.Range(.Value2).Value2 + 1
            End With
        End If
    
    ws_exit:
        Application.EnableEvents = True
    End Sub
    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1