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
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,396
Messages
5,511,102
Members
408,825
Latest member
Goncalves74

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top