Macros-count the last row & use the results

lkcred

New Member
Joined
Feb 19, 2014
Messages
23
I want to use the value of the last row found into a range using For Each...In [A:A]...in other words I want the range to stop at the last cell w/content in it...

'***Find last row
LastRow = Cells(Rows.Count, 1).End(xlUp).Row

'***Modify Data In Cells
For Each nb In [A:A] or LastRow.Rows
If nb.Value Like "*description *" Then
nb.Cells.Font.Bold = True
End If
Next nb

I want the loop to stop at the last row it found...then it moves to the next part of the code...
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Okay... update below in the code:-
For Each nb In Range("A1:A" & LastRow)

and try again.

Regards,
DILIPandey
 
Upvote 0
Change lastrow to range

Code:
'***Find last row
set LastRow = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)

'***Modify Data In Cells
For Each nb In LastRow

If nb.Value Like "*description *" Then
nb.Cells.Font.Bold = True
End If
Next nb
 
Upvote 0
lkcred,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?

Sample raw data:


Excel 2007
A
1Title C
2A2
3My description of something
4A4
5A5
6Your description of something else
7A7
8A8
9A9
10My description of something else
11A11
12
Sheet1


After the macro:


Excel 2007
A
1Title C
2A2
3My description of something
4A4
5A5
6Your description of something else
7A7
8A8
9A9
10My description of something else
11A11
12
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub Test()
' hiker95, 02/19/2014, ME758634

Dim c As Range
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  If c Like "*description *" Then c.Font.Bold = True
Next c

End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Test macro.
 
Upvote 0
lkcred,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?

Hiker95,

Excel 2007, thank you for the welcome!

Sample raw data:

Excel 2007
A
Title C
A2
My description of something
A4
A5
Your description of something else
A7
A8
A9
My description of something else
A11

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

[TD="align: center"]10[/TD]

[TD="align: center"]11[/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1



After the macro:

Excel 2007
A
Title C
A2
My description of something
A4
A5
Your description of something else
A7
A8
A9
My description of something else
A11

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

[TD="align: center"]10[/TD]

[TD="align: center"]11[/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1



Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub Test()
' hiker95, 02/19/2014, ME758634

Dim c As Range
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  If c Like "*description *" Then c.Font.Bold = True
Next c

End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Test macro.

I'm using 2007, thank you for the welcome...
 
Upvote 0
lkcred,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0
Hiker95,

I have another issue now...I'm trying to "c[FONT=Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif]oncatenate" the contents of 2 cells.
1)needs to go through & look for an cell containing FE* or Vlan*
2)once the FE* or Vlan* are found then i want to "
[/FONT][FONT=Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif]merge" the contents of the found cell and the next cell below it...
3)moved to a new cell...

Here is what I have, it doesn't work:
[/FONT]'***combine data in each cell & move them to new location
For Each i In [A1:A4000]
If i.Value Like "FE*" Or i.Value Like "Vlan*" Then
Range("B1").Select
ActiveCell.FormulaR1C1 = "=RC[-1]&"" ""&R[1]C[-1]&"""""
End If
Next i
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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