VBA example - Excel 2007: goto cells in Excel sheet


VBA code to go to cells in Excel sheet

When you work with may Excel worksheets, you may need to go to any sheet and any cells in this sheet immediately. This can be time consuming if you do it manually. However, this can be done fast with VBA code. The VBA program created in this example allows the user to jump to a specific cell or range of cells in any worksheet in a few seconds.


To run this VBA example code,  you will need a Form, a CommandButton, two ComboBoxes.

VBA for Excel: VBA example code to go to any cells in any worksheets

VBA code for this example:


Option Explicit
Dim shName As String
Dim rng As String
Private Sub ComboBox1_Change()
   shName = ComboBox1.Value
End Sub  
Private Sub ComboBox2_Change()  
  
rng = ComboBox2.Value

End Sub  
Private Sub CommandButton1_Click()   
  
Application.Goto Worksheets(shName).Range(rng), True
   
End Sub
 
Private Sub UserForm_Initialize()   
 
Dim i As Integer
  
 
For i = 1 To Worksheets.Count 'populate worksheet names
   
    
ComboBox1.AddItem Worksheets(i).Name
 
      
Next
    ComboBox1.ListIndex = 0     'sample ranges  
 
For i = 1 To 20
 
     
ComboBox2.AddItem "A" & i
 
     
Next
 
  
ComboBox2.ListIndex = 0

End Sub

Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.