Range syntax

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Can any one please tell me the right syntax for this.

Range(Cells(7, 11), Cells(p1, 11)).Select
Selection.Rows.group

I got error -

1004
Application defined or object defined error
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This worked for me

Code:
Sub test()
Dim p1
p1 = 15
MsgBox p1
Rows("7:" & p1).Group
End Sub
 
Upvote 0
Off course this will work Sir.
coz we directly mentioned the value to p1.

In this case we try get the cells value in p1 which unble to read the cell value even we had given a proper markup to pick the value.
 
Upvote 0
I again posted the code

Public Function tester()

Dim iam As Long
Dim jam

Dim p1 As Integer
Dim p2 As Integer
Dim p3 As Integer
Dim p4 As Integer
Dim p5 As Integer
Dim p6 As Integer
Dim p7 As Integer

iam = Range("K" & Rows.Count).End(xlUp).Row

For jam = 7 To iam

If Cells(jam, 11) = 2 Then
p1 = Cells(jam - 1, 11) '............last 1's
Else
If Cells(jam, 11) = 3 Then
p2 = Cells(jam - 1, 11) '............last 2's
Else
If Cells(jam, 11) = 4 Then
p3 = Cells(jam - 1, 11) '............last 3's
Else
If Cells(jam, 11) = 5 Then
p4 = Cells(jam - 1, 11) '............last 4's
Else
If Cells(jam, 11) = 6 Then
p5 = Cells(jam - 1, 11) '............last 5's
Else
If Cells(jam, 11) = 7 Then
p6 = Cells(jam - 1, 11) '............last 6's
Else
If Cells(jam, 11) = "" Then
p7 = Cells(jam - 1, 11) '............last 7's
End If
End If
End If
End If
End If
End If
End If
Next

MsgBox p1
Rows("7:" & p1).Group - error "Type Mismatch"

Rows("p1:" & p2).Group

Rows("p2:" & p3).Group

Rows("p3:" & p4).Group

Rows("p4:" & p5).Group

Rows("p5:" & p6).Group

Rows("p6:" & p7).Group

End Function
 
Upvote 0

Forum statistics

Threads
1,215,726
Messages
6,126,498
Members
449,316
Latest member
sravya

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