ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rename a range of cells with a macro (https://www.excelbanter.com/excel-programming/393022-rename-range-cells-macro.html)

JakeShipley2008

Rename a range of cells with a macro
 
If someone is able to help, I need a macro that will select a given range of
cells then convert them to a new name: See example

If C7:C20 is = 0.1 then replace cell contents with 625

Basically, I need to replace the contents of all cells in a given range
(that contain data) with a constant number like 625. If the cell is blank I
want to leave it blank.
--
Jake

PCLIVE

Rename a range of cells with a macro
 
Adjust your range as needed.

Sub test()
For Each cell In Range("A1:A5")
If cell.Value < "" _
Then
cell.Value = 625
Else
End If
Next cell
End Sub

HTH,
Paul


"JakeShipley2008" wrote in
message ...
If someone is able to help, I need a macro that will select a given range
of
cells then convert them to a new name: See example

If C7:C20 is = 0.1 then replace cell contents with 625

Basically, I need to replace the contents of all cells in a given range
(that contain data) with a constant number like 625. If the cell is blank
I
want to leave it blank.
--
Jake




JakeShipley2008

Rename a range of cells with a macro
 
Thank you so much that worked like a charm, one last question and I should
have it.

I am attaching the macro I am using, additionally I would like to do the
same thing but with I would like to select more ranges and add more cell
values such as the next line I would add would be for E3:E200 and then for
each cell in range D7:D200 make the value 615. Hopefully this makes sense - I
have to add about an additional 70 lines much like I am describing now.

If you can help I would greatly appreciate it.
--
Sub MoveActiveUSL()

lastrow = Sheets("Specs"). _
Cells(Rows.count, "C").End(xlUp).Row
Range("C" & (lastrow + 1)).Select

Sheets("Data Transfer").Select
Range("D3:D200").Select
Selection.Copy
Sheets("Specs").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
lastrow = Sheets("Specs"). _
Cells(Rows.count, "C").End(xlUp).Row
Range("C" & (lastrow + 1)).Select
For Each cell In Range("c7:c200")
If cell.Value < "" _
Then
cell.Value = 625
Else
End If
Next cell
With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.count, "C").End(xlUp).Row

For Lrow = EndRow To StartRow Step -1

If IsError(.Cells(Lrow, "C").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "C").Value = "" Then .Rows(Lrow).Delete

End If
Next
End With


End Sub


Jake


"PCLIVE" wrote:

Adjust your range as needed.

Sub test()
For Each cell In Range("A1:A5")
If cell.Value < "" _
Then
cell.Value = 625
Else
End If
Next cell
End Sub

HTH,
Paul


"JakeShipley2008" wrote in
message ...
If someone is able to help, I need a macro that will select a given range
of
cells then convert them to a new name: See example

If C7:C20 is = 0.1 then replace cell contents with 625

Basically, I need to replace the contents of all cells in a given range
(that contain data) with a constant number like 625. If the cell is blank
I
want to leave it blank.
--
Jake






All times are GMT +1. The time now is 05:35 PM.

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