Call cell in vba with var

ncfennem

New Member
Joined
Nov 30, 2018
Messages
1
I have this set of code and it's saying I have a global var error and if by chance you have a way to make this code any less complicated that would also be appreciated.
Code:
Sub test_if_statemnts()
'
' test_if_statemnts Macro
'


'
keybox1 = ThisWorkbook.Sheets("contact").Range("B5")
keybox2 = ThisWorkbook.Sheets("contact").Range("B10")
keybox3 = ThisWorkbook.Sheets("contact").Range("B15")
keybox4 = ThisWorkbook.Sheets("contact").Range("B20")
keybox5 = ThisWorkbook.Sheets("contact").Range("B25")
keybox6 = ThisWorkbook.Sheets("contact").Range("B30")
keybox7 = ThisWorkbook.Sheets("contact").Range("B35")
keybox8 = ThisWorkbook.Sheets("contact").Range("B40")
keybox9 = ThisWorkbook.Sheets("contact").Range("B45")
keybox10 = ThisWorkbook.Sheets("contact").Range("B50")


If [F1] = keybox1 Then
Copy ("A5")
    ElseIf [F8] = keybox2 Then
    Copy ("A10")
    ElseIf [F8] = keybox3 Then
    Copy ("A15")
    ElseIf [F8] = keybox4 Then
    Copy ("A20")
    ElseIf [F8] = keybox5 Then
    Copy ("A25")
    ElseIf [F8] = keybox6 Then
    Copy ("30")
    ElseIf [F8] = keybox7 Then
    Copy ("35")
    ElseIf [F8] = keybox8 Then
    Copy ("40")
    ElseIf [F8] = keybox9 Then
    Copy ("45")
    ElseIf [F8] = keybox10 Then
    Copy ("50")
    End If
    End Sub
    
Function Copy(x As String) As String
y = where(x)




End Function
Function where(x As String) As String
Sheets("contact").Select
ActiveSheet.Range("x").Select                        <-----------------------------------------------------------------------
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select


End Function
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Well, your initial sub won't work, because it's coded incorrectly.
This
Code:
If [F1] = keybox1 Then
Copy ("A5")

needs to be

Code:
If [F1] = keybox1 Then
Range("A5").copy
I'd also stick to one construct. Either use [f5] or Range("f1") throughout the code

finally A Function can't select anything, it returns a result !
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,658
Latest member
GStorm

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