Problem with Macro setting range

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
I have this macro:
Rich (BB code):
Sub ExampleTesting()
Dim LR As Long, i As Long, j As Long, ct As Integer
LR = Sheets("sheet2").Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR Step 1
    j = j + 1
    ct = UBound(Split(Sheets("sheet2").Range("C" & j).Text, " ")) + 1
    If ct < 2 Then
    Sheets("sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = _
Sheets("sheet2").Range("A" & j: "D" & j).Value
    End If
Next i
End Sub
What am I doing wrong? Any suggestions?

Thanks

Nicole
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I have this macro:
Rich (BB code):
Sub ExampleTesting()
Dim LR As Long, i As Long, j As Long, ct As Integer
LR = Sheets("sheet2").Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR Step 1
    j = j + 1
    ct = UBound(Split(Sheets("sheet2").Range("C" & j).Text, " ")) + 1
    If ct < 2 Then
    Sheets("sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = _
Sheets("sheet2").Range("A" & j: "D" & j).Value
    End If
Next i
End Sub
What am I doing wrong? Any suggestions?

Thanks

Nicole

Maybe..:

Code:
Sheets("sheet2").[COLOR=red]Range("A" & j & ":" & "D" & j)[/COLOR].Value
 
Upvote 0
On the same lines this won't work:

Code:
Dim j As Long
j = 3
Sheets("sheet2").Range("A" & j & ":" & "D" & j).Select

Why? and how do I fix it. Thanks
 
Upvote 0
I did get this to select range "a3:d3"

Does that help?

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
    Dim j As Long
    j = 3
    Range("A" & j & ":" & "d" & j).Select
   ' Range("A3:D3").Select
End Sub
 
Upvote 0
If Sheet2 is not the active sheet you'll need

Code:
Application.Goto Sheets("sheet2").Range("A" & j & ":" & "D" & j)
 
Upvote 0
Thanks Vog, I was just in the help file trying to figure out the sheets(2) problem.

I greatly appreciate these great questions along with the great answers.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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