1. The code to change the value of each cell of the name range at the same time
Sub Change_the_Value_of_Each_cell_in_Named_Range()
Dim NameRange As Range
Set NameRange = Range("SALES")
Dim Eachcell As Range
For Each Eachcell In NameRange
Eachcell.Value = "Sales" & "2017"
Next Eachcell
MsgBox "Done"
End Sub
2. Let's Say You have a list of Named Range in Sheet3 where you want to change the value of each Named Range with the Same Format
Sub Change_The_Value_of_Each_Named_Range()
Dim I As Long
I = 2
Dim SheetName As String
SheetName = "Sheet3"
Dim TargetRange As Range
Do Until Sheets(SheetName).Cells(I, 1).Value = vbNullString
Set TargetRange = Range(Sheets(SheetName).Cells(I, 1).Value)
TargetRange.Value = Sheets(SheetName).Cells(I, 1).Value & VBA.Format(Sheets(SheetName).Range("B6").Value, "YYYY")
I = I + 1
Loop
End Sub
3. TO RENAME THE WHOLE NAMED RANGES with EXACT FORMAT
Sub Rename_The_Name_Range()
Dim SheetName As String
SheetName = "Sheet3"
Dim TargetSheet As Worksheet
Set TargetSheet = Sheets(SheetName)
Dim TargetNamedRange As Name
Dim CurrentName As String
Dim Iname As String
Dim OriginalNamePlace As Integer
Dim HelperString As String
For Each TargetNamedRange In ThisWorkbook.Names
Iname = TargetNamedRange.Name
If VBA.InStr(1, Iname, "_") = 0 Then
CurrentName = Iname & VBA.Format(VBA.Date, "_yyyy")
ThisWorkbook.Names(Iname).Name = CurrentName
Else
OriginalNamePlace = VBA.InStr(1, Iname, "_")
HelperString = VBA.Left(Iname, OriginalNamePlace - 1)
CurrentName = HelperString & VBA.Format(VBA.Date, "_yyyy")
ThisWorkbook.Names(Iname).Name = CurrentName
End If
Next TargetNamedRange
MsgBox "Done"
End Sub
Subscribe to:
Post Comments (Atom)
IsValidPasswordString Function
'Following function will verify if the password string contains following characters or not? Rem : List of Characters Group - ASCII Rem ...
-
Here is the complete VBA code to import XML Data into the Excel Workbook in a completely dynamic approach. Look at the following video. ...
-
Hello Mates, When you work with Userform in Excel VBA, usually sometimes you need to retrieve or reflect currency figure in the Userfo...
-
'Following function will verify if the password string contains following characters or not? Rem : List of Characters Group - ASCII Rem ...
No comments:
Post a Comment