VBA - working with multiple variables and columns

salman94

New Member
Joined
Jun 7, 2018
Messages
21
Hi,

I have the following code with which I am getting error with the red text:

Dim rngTradeDates As Range
Dim dateCol As Range
Dim cl As Range


Set rngTradeDates = Range("TradeDates")
Set dateCol = Range("J1")


For Each cl In rngTradeDates.Cells


dateCol.Value = "Net Positions as of" & " " & cl.Value
dateCol.Font.Bold = True
Set dateCol = dateCol.Offset(, 3)

Dim rngfunds As Range
Dim fundr As Range

Set rngfunds = Range(Range("G2"), Range("G2").End(xlDown))
For Each fundr In rngfunds.Cells
Range("J" & fundr).Value = Application.WorksheetFunction.CountIfs(Sheets("Pending Transactions Count").Range("I:I"), cl.Value, _
Sheets("Pending Transactions Count").Range("AT:AT"), "*" & fundr.Value & "*") - Application.WorksheetFunction.CountIfs(Sheets("Pending Transactions Count").Range("I:I"), _
cl.Value, Sheets("Pending Transactions Count").Range("AU:AU"), "*" & fundr.Value & "*")
Range("K" & fundr).Value = Range("H" & fundr).Value + Range("J" & fundr).Value​
Next fundr​

Next cl

It may be complicated so let me briefly explain. I am using the countifs function to get a number from a column from another sheet called "Pending Transactions Count" and subtracting another number from a different column from "Pending Transactions Count". Each countifs function has 2 criteria.

I think my problem is in the way I have set up the variables and dimming them. Also I would like to repeat this formula for each dateCol column. Let me know if you have any questions.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try
Code:
fundr.offset(,3).Value = Application.WorksheetFunction.CountIfs...
and
Code:
fundr.Offset(, 4).Value = fundr.Offset(, 1).Value + fundr.Offset(, 3).Value
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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