ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add Sheet Name to Cell in Worksheet (https://www.excelbanter.com/excel-programming/375606-add-sheet-name-cell-worksheet.html)

ploddinggaltn

Add Sheet Name to Cell in Worksheet
 
I would like to add the sheet name to cell H in the worksheet but only those
rows that have text in them. How would I do that with code? Thanks

Tom Ogilvy

Add Sheet Name to Cell in Worksheet
 
Have text where in the row? Anywhere or in a single columnn

assume column G and the text are constants

set rng = columns(7).specialcells(xlconstants,xltextvalues)
set rng1 = Intersect(rng.entireRow, Columns(8))
rng1.Value = Activesheet.name

--
Regards,
Tom Ogilvy


"ploddinggaltn" wrote:

I would like to add the sheet name to cell H in the worksheet but only those
rows that have text in them. How would I do that with code? Thanks


Sandy

Add Sheet Name to Cell in Worksheet
 
do you mean column H and text in any cell in the row?

If so:

Sub AddSheetName()
Dim mCell As Range, mRow As Range
For Each mCell In Range("H:H")
For Each mRow In Range(mCell, _
Cells(mCell.Row, Columns.Count).End(xlToLeft).Address)
If Not mRow.Value = Empty Then
mCell.Value = ActiveSheet.Name
End If
Next mRow
Next mCell
End Sub


Sandy


ploddinggaltn wrote:
I would like to add the sheet name to cell H in the worksheet but only those
rows that have text in them. How would I do that with code? Thanks




All times are GMT +1. The time now is 11:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com