NYFashionToGo
Technical User
Hello, Thanks for looking at this post. I managed to scrape together then change & alter, and then change much and alter even more and then execute some code. I got it to work. There is one thing I am stuck with and could use some assitance.
This code is specifically for Naming regions in Excel sheet. In an attempt to Parse csv files and Txt and write code that will Float. Be more flexible later on. I have a problem with the source of my file downloads constantly changing position of the fields and it is giving me issues. So I wanted to programicly name each region based on sheet name and header name. This way when i write code later I can call that region even if the position changed... There may be other ways to achieve this. This is only way I could think of to execute this.
Where I could use help is with the 2000 Rows it selects down the column. I would like to change that so that floats with the data as well. If it ends on row 58. It stops there. If it ends on row 3023 it stops there.... Can anyone help? Hopefully you understand what I mean.
Thanks
Here is the Code:
Sub CreateNames()
Rows("1:1").Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Dim strRangeName As String, strWorksheetName As String
Dim intCounter As Integer, strRangeFormula As String
Dim strcolumn As String, strR1C1Formula As String
Dim strA1Formula As String
For intCounter = 1 To 50
strWorksheetName = ActiveSheet.Name
strR1C1Formula = "R1C" & Format(intCounter + 0, "#0")
strA1Formula = Application.ConvertFormula(Formula:=strR1C1Formula, FromReferenceStyle:=R1C1, ToReferenceStyle:=xlA1)
strRangeName = strWorksheetName & Format(Range(strA1Formula), "@")
strcolumn = "C" & Format(intCounter + 0, "#0")
strRangeFormula = "=" & strWorksheetName & "!R2" & strcolumn & ":R2000" & strcolumn
ActiveWorkbook.Names.Add Name:=strRangeName, RefersToR1C1:=strRangeFormula
Next intCounter
This code is specifically for Naming regions in Excel sheet. In an attempt to Parse csv files and Txt and write code that will Float. Be more flexible later on. I have a problem with the source of my file downloads constantly changing position of the fields and it is giving me issues. So I wanted to programicly name each region based on sheet name and header name. This way when i write code later I can call that region even if the position changed... There may be other ways to achieve this. This is only way I could think of to execute this.
Where I could use help is with the 2000 Rows it selects down the column. I would like to change that so that floats with the data as well. If it ends on row 58. It stops there. If it ends on row 3023 it stops there.... Can anyone help? Hopefully you understand what I mean.
Thanks
Here is the Code:
Sub CreateNames()
Rows("1:1").Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Dim strRangeName As String, strWorksheetName As String
Dim intCounter As Integer, strRangeFormula As String
Dim strcolumn As String, strR1C1Formula As String
Dim strA1Formula As String
For intCounter = 1 To 50
strWorksheetName = ActiveSheet.Name
strR1C1Formula = "R1C" & Format(intCounter + 0, "#0")
strA1Formula = Application.ConvertFormula(Formula:=strR1C1Formula, FromReferenceStyle:=R1C1, ToReferenceStyle:=xlA1)
strRangeName = strWorksheetName & Format(Range(strA1Formula), "@")
strcolumn = "C" & Format(intCounter + 0, "#0")
strRangeFormula = "=" & strWorksheetName & "!R2" & strcolumn & ":R2000" & strcolumn
ActiveWorkbook.Names.Add Name:=strRangeName, RefersToR1C1:=strRangeFormula
Next intCounter