PDA

View Full Version : How to rename cells



tharindudk
01-29-2014, 06:40 PM
Hi,

I have created a worksheet where I enter number of sites and using a Template in Sheet 2, Column E, this template get copied to next empty columns.

That is, If I enter 3 in No of Store sheet 1, In sheet 2, Columns F, G and H get created using the Template in Column E.

The problem I have is, I am hiding dows depending on the selection from drop down lists. When this is the case, I want to hide rows of columns individualy, but I have written the code to hide rows based on Cell Names used in Column E.

Is there a way to hide unhide cells as required when I create a column. I know If I manualy rename the Cells, it will work, but instead what if every time a column get gopied, rename the cells to Clothes_type_1, Clothes_type_2, Clothes_type-3 since original name of the Cell is "Clothes_type".

Also instead of hiding, crossing out is also fine.

I have made a simple template and attached it here. any help is appriciated.

tharindudk
01-29-2014, 10:10 PM
HI,

I managed to rename the cells as required using the code below.


Sub NameCell()

Sheets("Sheet1").Range("Number_Sites").Value = Sheets("Sheet1").Range("Number_Sites").Value + 1

Dim rng As Range, prev_cnt As Integer, x
Set rng = Sheets("Sheet1").Range("Number_Sites")
prev_cnt = rng
Application.DisplayAlerts = 0

x = prev_cnt
ActiveWorkbook.Sheets("Sheet2").Activate
Sheets("Sheet2").Range("NIKE").Offset(0, x).Select
ActiveCell.Name = "NIKE_" & x
Sheets("Sheet2").Range("Clothes_type").Offset(0, x).Select
ActiveCell.Name = "Clothes_type" & x

ActiveWorkbook.Sheets("Sheet1").Activate
End Sub


Now I am trying to but a Strike through the result ( If User choose "Mens" for Gender, and NOT "Pants", Then Strike though the Result "NIKE". This works for the template in column E only using this code.


Private Sub Worksheet_Change(ByVal Target As Range)

Range("NIKE").Font.Strikethrough = False

If Range("Clothes_type").Value <> "Pants" Then
Range("NIKE").Font.Strikethrough = True

End If
End Sub



I want to modify it so that It works for any "NIKE_" & x.

I tried the below code, but I cant do


Range("NIKE_" & x).Font.Strikethrough = False






Private Sub Worksheet_Change(ByVal Target As Range)

Range("NIKE_" & x).Font.Strikethrough = False

If Range("Clothes_type_" & x).Value <> "Pants" Then
Range("NIKE_" & x").Font.Strikethrough = True

End If
End Sub



Any Help is appriciated