# Another Range Calculation with cell references

#### Spikenaylor

##### Board Regular
Hi, I am having a problem getting this to work.

Code:
``````Dim CellsFilled As Integer, cref1 As String, cref2 As String, cref3 As String, cref4 As String, cref5 As String, rng As Range, rng1 As String, rng2 As String
cref1 = "C2"
cref2 = "C7"
cref3 = "D"
CellsFilled = GetCellsFilled(cref1, cref2) ' gets a count of how many cells are filled with data, in this example, it is 5
cref4 = cref1 & ":" & cref3 & CellsFilled
cref5 = "H2:J5"
Set rng = ActiveSheet.Range(cref4, cref5)  ' [COLOR=#FF0000]This does not work
[/COLOR]'Set rng = ActiveSheet.Range(cref4)  '[COLOR=#00FF00] This works[/COLOR]
'Set rng = ActiveSheet.Range(cref5)  '[COLOR=#00FF00] This works[/COLOR]
'Set rng = ActiveSheet.Range("C2:D5, H2:J5")    '[COLOR=#00FF00] This works[/COLOR]
Call checkcells(rng, CellsFilled)``````

Code:
``````Sub checkcells(rng As Range, CellsFilled As Integer)
Dim r As Range, a As Integer
Dim bCellsFilled As Boolean
bCellsFilled = True
For Each r In rng
If r.Value = "" Then
bCellsFilled = False
End If
Next r
If bCellsFilled = True Then
MsgBox " All cells in the first " & CellsFilled - 1 & " rows of the batch contain data"
Else: MsgBox " Some Cells in the first 3 rows of the batch are Empty, please recheck before cicking the button"
End
End If

End Sub``````

### Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

#### VoG

##### Legend
Try

Code:
``Set Rng = ActiveSheet.Range(cref4 & "," & cref5)``

#### Spikenaylor

##### Board Regular
Doh,

Why is it the simplist things confuse you.

Many Thanks
Mike

#### snb_

##### Well-known Member
simplest ?

Code:
``Set rng = ActiveSheet.cells.specialcells(2)</pre>``

Replies
10
Views
433
Replies
1
Views
164
Replies
2
Views
270
Replies
5
Views
531
Replies
4
Views
309

1,195,590
Messages
6,010,611
Members
441,558
Latest member
lambierules

### 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.

### Which adblocker are you using?

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

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