Reference offset cell during loop

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
723
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have this bit of code -
VBA Code:
Dim email As Variant
Set email = Sheets("Sheet0").Range("H4:H" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)

Dim status As Variant
Set status = Sheets("Sheet0").Range("D4:D" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)

Dim course1 As Variant
Set course1 = Sheets("Sheet0").Range("A4:A" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)
    
lr2 = 5
For x = 0 To lr2

'Range("I2").Offset(0, x) = Range("I1").Offset(0, x)
'Range("I2").Offset(0, x) = "=countifs(" & email.Address(external:=True) & ",G2," & course1.Address(external:=True) & ",Range("I1").Offset(0, x)," & status.Address(external:=True) & ",""Completed"")"

Next x

This is the result I'm looking for using the loop above. I can't figure out how to work Range("I1").Offset(0, x) into my looped formula.

Has_Has_Not_Taken_Report_04132022.xlsx-1.xls
IJKLMN
1619156B619155M5B619155M6B619155M7B619156BVCIWB01SSFIA22
2110011
Report
Cell Formulas
RangeFormula
I2:N2I2=COUNTIFS(Sheet0!$H$4:$H$898,$G$2,Sheet0!$A$4:$A$898,I1,Sheet0!$D$4:$D$898,"Completed")
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I think I figured it out

VBA Code:
Dim email As Variant
Set email = Sheets("Sheet0").Range("H4:H" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)

Dim status As Variant
Set status = Sheets("Sheet0").Range("D4:D" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)

Dim course1 As Variant
Set course1 = Sheets("Sheet0").Range("A4:A" & Sheets("Sheet0").Range("A" & Rows.Count).End(xlUp).Row)
    
Dim course As Variant

lr2 = 5
For x = 0 To lr2

Set course = Range("I1").Offset(0, x)
Range("I2").Offset(0, x) = "=countifs(" & email.Address(external:=True) & ",G2," & course1.Address(external:=True) & "," & course.Address(external:=True) & "," & status.Address(external:=True) & ",""Completed"")"

Next x
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,292
Members
449,149
Latest member
mwdbActuary

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