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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
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
 

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
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
 

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
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
 

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554

ADVERTISEMENT

Your right. strange :). thanks
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
If Sheet2 is not the active sheet you'll need

Code:
Application.Goto Sheets("sheet2").Range("A" & j & ":" & "D" & j)
 

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,565
Messages
5,659,569
Members
418,508
Latest member
deepakfer

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
Top