Another Range Calculation with cell references

Spikenaylor

Board Regular
Joined
Apr 14, 2013
Messages
115
Office Version
  1. 365
Platform
  1. Windows
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Doh,

Why is it the simplist things confuse you.

Hadn't evan thought of that.
Many Thanks
Mike
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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