View Full Version : Help with vba macro
chase
03-10-2012, 11:38 PM
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.
dazwm
03-11-2012, 02:04 AM
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.
chase
03-11-2012, 03:19 AM
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..: pray2:
Please note that I used the default CodeName.  Try:
 
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
 
Hope that helps,
 
Mark
ACK!
 
The above goes in Sheet1's code module and presumes activex controls.
chase
03-11-2012, 04:48 AM
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..:think:
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..:think:
 
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?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.