Select Cells based on other Cells Value

Rahulwork

Active Member
Joined
Jun 9, 2013
Messages
284
Hello Everyone,

I am working on database and need your help in one macro.

I have one drop down linked with V1 and have one search box.

V1 will be the country name. So i want

If V1 is australia then C8:P9 should be selected and cursor automatically reach on C3.
Same if V1 is Austria then C12:P13 should be selected and cursor automatically reach on C12.

I want this macro on button. Please help
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Just did this macro code, it's working fine but it's not working like hyperlink

Sub Rectangle1_Click()


Application.ScreenUpdating = False




Dim Ash As Worksheet
Dim stxt1 As String
Dim stxt2 As String
Dim stxt3 As String




Set Ash = ActiveWorkbook.ActiveSheet




stxt1 = "A"
stxt2 = "B"
stxt3 = "C"




If Ash.Range("J1") = stxt1 Then
With Ash
.Range("C40:P40").Select
End With
End If

If Ash.Range("J1") = stxt2 Then
With Ash
.Range("C45:P45").Select
End With
End If

If Ash.Range("J1") = stxt3 Then
With Ash
.Range("C50:P50").Select
End With
End If

Application.ScreenUpdating = True








End Sub
 
Upvote 0
Where does the acting like a Hyperlink come in and what do you mean by it?

What exactly does reach mean in "cursor automatically reach on C12"mean?

Can you try and explain exactly what else you want the code to do?

Btw, I would probably use Select case for the test i.e.

Code:
Sub V1dropdown()
    Select Case Range("V1").Value
       
        Case "Australia"
            Range("C8:P9").Select
      
        Case "Austria"
            Range("C12:C13").Select
            
        Case Else

    End Select
End Sub

and there is no point using a With statement if you are only doing 1 action.

Finally what are you doing with the Select afterwards as you don't normally need to select in code?
 
Last edited:
Upvote 0
How about
Code:
Sub Rectangle1_Click()

Application.ScreenUpdating = False

    Dim Ash As Worksheet
    Dim stxt1 As String
    Dim stxt2 As String
    Dim stxt3 As String
    
    Set Ash = ActiveWorkbook.ActiveSheet
    
    stxt1 = "A"
    stxt2 = "B"
    stxt3 = "C"
    
    If Ash.Range("J1") = stxt1 Then
        Application.Goto Range("C40:P40"), True
    ElseIf Ash.Range("J1") = stxt2 Then
        Application.Goto Range("C45:P45"), True
    ElseIf Ash.Range("J1") = stxt3 Then
        Application.Goto Range("C50:P50"), True
    End If

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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