Find string, replace, and increment with loop?

mdutton27

New Member
Joined
Nov 3, 2020
Messages
7
Office Version
  1. 365
Platform
  1. MacOS
I'm realising that I'm clearly not a coder more and more every day I try, so would appreciate some help.

I have an excel worksheet that has unique and repetitive column headings. Row 1 in my mini-sheet is my raw column headings that I need to record into what I've posted in Row 2. What I'd like to do is, for certain values like "Timestamp Start Task" I'd like to incrementally relabel these T1_Starttime, T2_Starttime, etc. You'll see there are quite a few that I need to incrementally relabel. There are others that I just need to relabel which I think I can figure out, but the loop part I cannot figure out for the life of me. If anyone is willing to help it would be appreciated, and if possible, I'd love to be able to do something along the lines of, if the column header in Row 1 is not changed as a part of the script then relabel those incrementally as "New value 1", "New value 2" etc.

What have I tried? Well I'm embarrassed as I've been adapting what I could find and this is the best I've gotten which hasn't worked ?
Sub Demo()

Application.ScreenUpdating = False
Dim i As Long, j As Long, str0 As String, str1 As String, str2 As String, str3 As String
Set Rng = Range("A1:ZA1")
On Error GoTo ErrExit
i = 0
str0 = "Task success"
str1 = "T"
str2 = "_Effectiveness"
str3 = str1 & j & str2

On Error GoTo 0
With Rng.Select
Selection.Find(what:=str0, After:=("A1"), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
End With
Do While .Find.Found
If .InRange(Rng) Then
.InsertAfter j + i
j = str3 + 1
.Find.Execute
Else
Exit Do
End If
Loop
End With
ErrExit:
Application.ScreenUpdating = True
MsgBox j & " verse references updated."
End Sub



junk.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBE
1 For the first task, you are required to log-in to the system with credentials provided by the moderator. Then locate the MUIQ widget at bottom of the screen. Try expanding and minimising it, as well as moving it to a place you are comfortable with. Task successTotal Task Time (sec)Number of ClicksStudy Completed?Number of Visited URLsPlugin IDTimestamp Task StartTimestamp Task End For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is useful ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is user friendly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I learned to use it quickly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am satisfied with it ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am confident that I completed the task successfully] Did you encounter any difficulty during this task? Please rate the level of difficulty you experienced; where 1) is Not difficult at all and 7) is Very difficult. [undefined] Please ask your moderator for the corresponding code: Any comments you'd like to provide regarding the previous task? Task1 group Time (sec) Your company just rolled out Performance Analytics to your organization with new dashboards, and capabilities to help monitor Incidents. They created a new dashboard for you called Incident Management. Please find it and add it to your favorites. Task successTotal Task Time (sec)Number of ClicksStudy Completed?Number of Visited URLsPlugin IDTimestamp Task StartTimestamp Task End For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is useful ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is user friendly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I learned to use it quickly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am satisfied with it ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am confident that I completed the task successfully] Did you encounter any difficulty during this task? Please rate the level of difficulty you experienced; where 1) is Not difficult at all and 7) is Very difficult. [undefined] Please ask your moderator for the corresponding code: Any comments you'd like to provide regarding the previous task? Task2 group Time (sec) Using the Incident Management dashboard, please find the Open Incidents by Priority and determine the delta in critical incidents from yesterday. Task successTotal Task Time (sec)Number of ClicksStudy Completed?Number of Visited URLsPlugin IDTimestamp Task StartTimestamp Task End For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is useful ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [It is user friendly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I learned to use it quickly ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am satisfied with it ] For the task you just completed, please indicate how strongly you agree with the following statements; where 1) is Strongly Disagree and 7) is Strongly Agree. [I am confident that I completed the task successfully] Did you encounter any difficulty during this task? Please rate the level of difficulty you experienced; where 1) is Not difficult at all and 7) is Very difficult. [undefined] Please ask your moderator for the corresponding code: Any comments you'd like to provide regarding the previous task? Task3 group Time (sec)
2T1_TaskT1_EffectivenessT1_Time_taskT1_ClicksT1_StudyCompleteT1_UrlsDeletemeT1_StarttimeT1-EndtimeT1_UsefulT1_UserFriendlyT1_LearnedT1_SatisfiedT1_ConfidentT1_Exp_DifficultyT1_DifficultyLevelT1_Pass_FailT1_CommentsT1_OverallTimeT2_TaskT2_EffectivenessT2_Time_taskT2_ClicksT2_StudyCompleteT2_UrlsDeletemeT2_StarttimeT2_EndtimeT2_UsefulT2_UserFriendlyT2_LearnedT2_SatisfiedT2_ConfidentT2_Exp_DifficultyT2_DifficultyLevelT2_Pass_FailT2_CommentsT2_OverallTimeT3_TaskT3_EffectivenessT3_Time_taskT3_ClicksT3_StudyCompleteT3_UrlsDeletemeT3_StarttimeT3_EndtimeT3_UsefulT3_UserFriendlyT3_LearnedT3_SatisfiedT3_ConfidentT3_Exp_DifficultyT3_DifficultyLevelT3_Pass_FailT3_CommentsT3_OverallTime
Sheet3
 

Attachments

  • 1652664506090.png
    1652664506090.png
    1,002 bytes · Views: 7

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It seems each task is in 19 columns sequence, and the below text array are repeated
Task,Effectiveness,Timetask,Clicks,StudyComplete,Urls,Deleteme,Starttime,-Endtime,Useful,UserFriendly,Learned,Satisfied,Confident,ExpDifficulty,DifficultyLevel,PassFail,Comments,OverallTime
Use this code:
VBA Code:
Option Explicit
Sub Demo()
Dim s, cell As Range
s = Split("Task,Effectiveness,Timetask,Clicks,StudyComplete,Urls,Deleteme,Starttime,Endtime,Useful, UserFriendly,Learned,Satisfied,Confident,ExpDifficulty,DifficultyLevel,PassFail,Comments,OverallTime", ",")
    For Each cell In Range("A2:BE2")
        cell.Value = "T" & Int((cell.Column - 1) / 19) + 1 & "_" & s(((cell.Column - 1) Mod 19))
    Next
End Sub
 
Last edited:
Upvote 0
Edit previous post:
I found that in column 7, it is "Deleteme", not "T1_Deleteme" ???
If yes, try:
VBA Code:
Option Explicit
Sub Demo()
Dim s, cell As Range
s = Split("Task,Effectiveness,Timetask,Clicks,StudyComplete,Urls,Deleteme,Starttime,Endtime,Useful, UserFriendly,Learned,Satisfied,Confident,ExpDifficulty,DifficultyLevel,PassFail,Comments,OverallTime", ",")
    For Each cell In Range("A2:BE2")
        cell.Value = IIf(cell.Column = 7, "", "T" & Int((cell.Column - 1) / 19) + 1 & "_") & s(((cell.Column - 1) Mod 19))
    Next
End Sub
 
Upvote 0
Edit previous post:
I found that in column 7, it is "Deleteme", not "T1_Deleteme" ???
If yes, try:
VBA Code:
Option Explicit
Sub Demo()
Dim s, cell As Range
s = Split("Task,Effectiveness,Timetask,Clicks,StudyComplete,Urls,Deleteme,Starttime,Endtime,Useful, UserFriendly,Learned,Satisfied,Confident,ExpDifficulty,DifficultyLevel,PassFail,Comments,OverallTime", ",")
    For Each cell In Range("A2:BE2")
        cell.Value = IIf(cell.Column = 7, "", "T" & Int((cell.Column - 1) / 19) + 1 & "_") & s(((cell.Column - 1) Mod 19))
    Next
End Sub
I will try this after this meeting, but thank you!
 
Upvote 0
Edit previous post:
I found that in column 7, it is "Deleteme", not "T1_Deleteme" ???
If yes, try:
VBA Code:
Option Explicit
Sub Demo()
Dim s, cell As Range
s = Split("Task,Effectiveness,Timetask,Clicks,StudyComplete,Urls,Deleteme,Starttime,Endtime,Useful, UserFriendly,Learned,Satisfied,Confident,ExpDifficulty,DifficultyLevel,PassFail,Comments,OverallTime", ",")
    For Each cell In Range("A2:BE2")
        cell.Value = IIf(cell.Column = 7, "", "T" & Int((cell.Column - 1) / 19) + 1 & "_") & s(((cell.Column - 1) Mod 19))
    Next
End Sub
So while I like what you did, I think I explained my problem poorly. What I need to do is loop through A1:BE1 and relabel that row to the string below, accounting for some unique column names which I'll just do a find/replace on. For example, column B through R will repeat in my actual excel book ten times, followed by two unique columns (S and T) before the next 17 columns that would be T2_xxxxxx.

I realise I'm asking a lot, so if it's too much just let me know.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top