Consulting

Results 1 to 7 of 7

Thread: Help with vba macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2012
    Posts
    3
    Location

    Question Help with vba macro

    can someone direct me a code where will i be able to view all the values in a column next after next using a command button where the values will be displayed using a label.

  2. #2
    VBAX Regular
    Joined
    Feb 2012
    Posts
    31
    Location
    Quote Originally Posted by chase
    can someone direct me a code where will i be able to view all the values in a column next after next using a command button where the values will be displayed using a label.
    Could you explain a bit better or provide a sample.

  3. #3
    VBAX Newbie
    Joined
    Mar 2012
    Posts
    3
    Location
    Quote Originally Posted by dazwm
    Could you explain a bit better or provide a sample.

    sorry..
    what i mean is...for example..i have a list of records in "sheet2" from range "A1 to A15" then, i want to display those values in "sheet1" using a label control and a command button..in which whenever i press the command button, the label control will display the values listed in "sheet2" ranging from "A1 to A15".

    hope you can help me here..

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Please note that I used the default CodeName. Try:

    [VBA]
    Option Explicit

    Private Sub CommandButton1_Click()
    Dim Cell As Range
    Dim sValues As String

    For Each Cell In Sheet2.Range("A1:A15")
    If Not Cell.Value = vbNullString Then
    sValues = sValues & Cell.Value & vbLf
    End If
    Next

    Me.Label1.Caption = Left(sValues, Len(sValues) - 1)
    End Sub[/VBA]

    Hope that helps,

    Mark

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    ACK!

    The above goes in Sheet1's code module and presumes activex controls.

  6. #6
    VBAX Newbie
    Joined
    Mar 2012
    Posts
    3
    Location
    Quote Originally Posted by GTO
    ACK!

    The above goes in Sheet1's code module and presumes activex controls.
    thanks for the help..it is working..but i forgot to mention that i need to display values one by one..so whenever i press the command button each time the display in label will change accordingly to the following values in sheet 2..

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by chase
    thanks for the help..it is working..but i forgot to mention that i need to display values one by one..so whenever i press the command button each time the display in label will change accordingly to the following values in sheet 2..
    Sorry - not sure I am following. Do you mean that you want the Label to only show one of the cells' value at a time? If so, is each click of the button to get the next cell's value?

Posting Permissions

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