Cells(2, Columns.Count).End(1)(1, 2).Value = n |/| difficult to manipulate "for me"

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone.
I think I don't need for this question to use XL2BB, if so, please let me know will more than grateful to do it.
with this code:
VBA Code:
Sub jumping_v2()
  Dim i As Long, n As Long
  Dim f As Range  
  For i = 2 To Range("B" & Rows.Count).End(3).Row  
    Set f = Range("B" & i).Resize(, 5).Find(1, , xlValues, xlWhole)   
    If Not f Is Nothing Then    
      Cells(2, Columns.Count).End(1)(1, 2).Value = n     
      n = -1
    End If
    n = n + 1
  Next
End Sub
I got this answer:
1682438633895.png

right beside my array is the answer, I really need my answer on T2
so I tried to change the line for:
VBA Code:
Sub jumping_v2()
  Dim i As Long, n As Long
  Dim f As Range
  
  For i = 2 To Range("B" & Rows.Count).End(3).Row
  
    Set f = Range("B" & i).Resize(, 5).Find(1, , xlValues, xlWhole)
   
    If Not f Is Nothing Then
    
            Cells(Rows.Count, "P").End(xlUp).Offset(1, 0).Value = n
      

      n = -1
    End If
    n = n + 1
  Next
End Sub
and this is what I got:
1682438797507.png

so what I am looking for is for:

1682438907227.png


dante_skip_April.xls
BCDEF
254232532
347133133
41012172633
5510193336
61013162127
778102429
8812202728
919153133
10511212528
1125132527
12912303236
13312192231
Sheet1

thank you for your understanding and time
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
What I imagined. The number of results reached the limit of excel columns.

I leave you an alternative, when 30 columns are completed it will start in next row:
VBA Code:
Sub jumping_v2()
  Dim i As Long, n As Long, col As Long, m As Long, j As Long
  Dim f As Range
  col = Columns("T").Column
  j = 2
  For i = 2 To Range("B" & Rows.Count).End(3).Row
    Set f = Range("B" & i).Resize(, 5).Find(5, , xlValues, xlWhole)
    If Not f Is Nothing Then
      Cells(j, col).Value = n
      n = -1
      col = col + 1
      m = m + 1
      If m = 30 Then   'Fit to the number you want.
        m = 0
        j = j + 1
        col = Columns("T").Column
      End If
    End If
    n = n + 1
  Next
End Sub

The result would be something like this:
1682593923882.png


I hope it is close to what you are looking for.
Sincerely
Dante Amor
 
Upvote 1
Solution
I'd say you need to offset the column within the loop but I don't know exactly how because I can't replicate your results with either code and that data. I get only one execution of the value setting line of code. Nor do I understand why you're counting the used rows in P and starting your offset from P. If I offset like
Cells(Rows.Count, "P").End(xlUp).Offset(1, 4).Value = n then I get one value in T. You might get what you're after with something like

x = 4
Cells(Rows.Count, "P").End(xlUp).Offset(0, x).Value = n
x = x +1
 
Upvote 0
Hi @montecarlo2012.

In your example I only see a single 1. But testing with the number 5, I find more values, the result is:
Dante Amor
ABCDEFGSTUVWX
1
2542325320240
347133133
41012172633
5510193336
61013162127
778102429
8812202728
919153133
10511212528
1125132527
12912303236
13312192231
14
Hoja1


I really need my answer on T2
We need another variable for the column counter, starting at column T:
VBA Code:
Sub jumping_v2()
  Dim i As Long, n As Long, col As Long
  Dim f As Range
  col = Columns("T").Column
  For i = 2 To Range("B" & Rows.Count).End(3).Row
    Set f = Range("B" & i).Resize(, 5).Find(5, , xlValues, xlWhole)
    If Not f Is Nothing Then
      Cells(2, col).Value = n
      n = -1
      col = col + 1
    End If
    n = n + 1
  Next
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0
Hello @montecarlo2012.
Modify something in the macro?
Do you have any cell with error?
Did you copy the entire macro?
As you can see in my post I put the result and I have no errors.
You can try it in a new file. With new data, copy the entire macro and come back here and tell me.

Cordially
Dante Amor
 
Upvote 0
Good morning Dante, and thank you again for your time
1/Modify something in the macro? = No
2/Do you have any cell with error? = I clear everything, clear formatting rules,
3/Did you copy the entire macro? =Yes
1682518507085.png

So now I am getting results and after again the debug sign show up and highlight this line.
You can try it in a new file|||| happen with another macro, doing that do not address the problem.

Thank you DanteAmor.
 
Upvote 0
So now I am getting results and after again the debug sign show up and highlight this line.
You can try it in a new file|||| happen with another macro, doing that do not address the problem.
I don't understand.
It works fine, but at other times it doesn't work?

I have no problem with the macro.
You can share your file to review what problem you have.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
DanteAmor,
Hello
Thanks for your time

Before we close this thread
the code work, the detail is:

In this way all those results,
don't let me check
the data in the way I need,
because, for example,
the first road I don't know now,
what number is referring to.
would be so helpful,
If you don't mind of course, to:

("for better understanding let me show you the column I add")
1682607227864.png


Column S.
I know this is not what you see in the dropbox, sorry,
what I was trying to do is using your code like

Set f = Range("B" & i).Resize(, 5).Find(1, , xlValues, xlWhole) display T2
Set f = Range("B" & i).Resize(, 5).Find(2, , xlValues, xlWhole) " T3
Set f = Range("B" & i).Resize(, 5).Find(3, , xlValues, xlWhole) " T4
---
---
until Set f = Range("B" & i).Resize(, 5).Find(36, , xlValues, xlWhole) display T37

I was thinking taking your code and copy and paste the line Set f and change it 36 times.
is a complex matter for me this kind of -->looping manipulation<--

then now, I don't know what value is referring to.
I know I didn't say this, "at the first place", sorry about it.

I never imaging you ask me for the whole work book,
"I am so happy you do that",
thank you.
 
Upvote 0

Forum statistics

Threads
1,215,345
Messages
6,124,408
Members
449,157
Latest member
mytux

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