Luis Diaz
asked on
Excel VBA: Add specific value on multiple columns v2
Hello experts,
I have the procedure reported at: https://www.experts-exchan ge.com/que stions/291 55959/Exce l-VBA-Add- specific-v alue-on-mu ltiple-col umns.html
I retested and I am having a little issue:
Please find bellow my test:
1-I report titi value in first inputbox
2-I report a;b;c in second inputbox
Issue:
I have the various headers replaced by value reported in first inputbox.
I don't understand as I have the following line:
I attached dummy file with Input sheet before running the procedure and Result sheet after I execute the procedure as reported in my test above.
Thank you for your help.
Dummy-file.xlsm
I have the procedure reported at: https://www.experts-exchan
Sub Add_Specific_String_Multiple_Columns()
Dim strCol As Variant
Dim strColList As String
Dim lngLastRow As Long, lngRow As Long
Dim strToReplaceWith As String
strToReplaceWith = InputBox("Please input the Value which should replace the values of the Reported Columns.")
If strToReplaceWith = "" Then
MsgBox "You didn't input any value.", vbExclamation
Exit Sub
End If
strColList = InputBox("Please report column letter(s) following by ; in which you want to apply procedure," _
& ": A for single column A;C;D for multiple columns", "Choose Column Letter(s)")
If strColList = vbNullString Then
MsgBox ("No input!")
Exit Sub
End If
For Each strCol In Split(strColList, ";")
If Not ValidCellReference(strCol) Then
MsgBox strCol & " is not a valid column letter.", vbExclamation
Exit Sub
End If
Next strCol
For Each strCol In Split(strColList, ";")
lngLastRow = Range(strCol & Rows.Count).End(xlUp).Row
Range(strCol & "2:" & strCol & lngLastRow).Value = strToReplaceWith
Next
End Sub
Function ValidCellReference(ByVal str As String) As Boolean
Dim rng As Range
On Error Resume Next
Set rng = Cells(1, str)
On Error GoTo 0
If Not rng Is Nothing Then ValidCellReference = True
End Function
I retested and I am having a little issue:
Please find bellow my test:
1-I report titi value in first inputbox
2-I report a;b;c in second inputbox
Issue:
I have the various headers replaced by value reported in first inputbox.
I don't understand as I have the following line:
Range(strCol & "2:" & strCol & lngLastRow).Value = strToReplaceWith
which states that replacewith starts as of row 2.I attached dummy file with Input sheet before running the procedure and Result sheet after I execute the procedure as reported in my test above.
Thank you for your help.
Dummy-file.xlsm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Subodh,
I tested and the procedure works but I have a little issue, I don’t know if this can be reviewed.
Attached I made a test in Current sheet. I reported: 20190826_064245 for first inputbox and A;B;D in second inputbox.
I have no data for column A, 1 rows populated for B and 5 for D. I understand that the procedure do this as it should check last used range by column.
I was wondering if there is a way to check the highest last used range of one of the column concerned by reported in inputbox 2 and replace for all columns.
I also attached dummy file with Expected sheet with same previous test. I expect to have rows populated till row 5 for all columns reported in inputbox 2.
Let me know what do you think.
Dummy-file-add-values-on-columns.xlsx
I tested and the procedure works but I have a little issue, I don’t know if this can be reviewed.
Attached I made a test in Current sheet. I reported: 20190826_064245 for first inputbox and A;B;D in second inputbox.
I have no data for column A, 1 rows populated for B and 5 for D. I understand that the procedure do this as it should check last used range by column.
I was wondering if there is a way to check the highest last used range of one of the column concerned by reported in inputbox 2 and replace for all columns.
I also attached dummy file with Expected sheet with same previous test. I expect to have rows populated till row 5 for all columns reported in inputbox 2.
Let me know what do you think.
Dummy-file-add-values-on-columns.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, Unable to test it right know.
I will keep you informed.
I will keep you informed.
ASKER
I tested last proposal and it works! Thank you very much for your help!
You're welcome!
ASKER
I will keep you informed.