How do I work with range?

Andresen

New Member
Joined
Nov 10, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi,
I will in the end try to use this Sub as a Function. (This will be like a multi Vlookup function.) But I cannot come through with the Range.

I try to run the test_Function() sub.
I get Compile error Type mismatch. And I cannot find why (see picture). This is the first time I use Range variables.

The data looks like this
1674649268499.png


Sub test_Function()
Call Calcdata("HH4:HN22", "VCM5D Reach 1.1", "Requirements", "", "", "", "")
End Sub



Sub Calcdata(Data_Range As Range, Target_Version As String, Variable1 As String, Variable2 As String, Variable3 As String, Variable4 As String, variable5 As String)

Dim Variable(1 To 5) As String
Dim VCol(1 To 5) As Long
Dim VTargetRow As Long
Dim i As Long
Dim ASheet As String
Dim VResult As Long

Variable(1) = Variable1
Variable(2) = Variable2
Variable(3) = Variable3
Variable(4) = Variable4
Variable(5) = variable5

ASheet = ActiveSheet.Name

For i = 1 To 5
If Not Variable(i) Then Call FindInputColumn(VCol(i), Variable(i), ASheet, 4)
Next i

Call FindInputRow(VTargetRow, Target_Version, ASheet, 1)
' Find each Variable in range and sum the different Variables

VResult = 0
For i = 1 To 5
If VCol(i) > 0 Then
VResult = VResult + ActiveSheet.Cells(VTargetRow, VCol(i)).Value
End If
Next i
' Calcdata = VResult

End Sub
 

Attachments

  • Range issue.PNG
    Range issue.PNG
    38.7 KB · Views: 7

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Your code is very hard to read and understand for me. From the first look, change this:
VBA Code:
Call Calcdata(Range("HH4:HN22"), "VCM5D Reach 1.1", "Requirements", "", "", "", "")
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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