I'm not an advanced VBA programmer. I'm working on an excel macro which will allow me to select a range(using input box) to clean the data(makes consistent with mySQL schema) on worksheet. I get this file from anther team and 1.) the order of columns is not fixed 2) levels of categories(there are few columns for categories like level1 level2 etc.) can be anything between 3-10. I'm now stuck with concatenating the columns for categories using "|" as a separator and put the values in first category column(level1). Please help me do this.
My code is like below:
Please do not suggest a UDF, I want to do this with macro. I must do this on files before importing them on SQL database, so a macro will be handy. Please ask if I failed to mention anything else.
My code is like below:
Code:
<code>Sub cleanData() Dim rngMyrange As Range Dim cell As Range On Error Resume Next Do 'Cleans Status column Set rngMyrange = Application.InputBox _ (Prompt:="Select Status column", Type:=8) On Error GoTo 0 'Is a range selected? Exit sub if not selected If rngMyrange Is Nothing Then End Else Exit Do End If Loop With rngMyrange 'with the range just selected .Replace What:="Dead", Replacement:="Inactive", SearchOrder:=xlByColumns, MatchCase:=False 'I do more replace stuff here End With rngMyrange.Cells(1, 1) = "Status" Do 'Concatenates Category Columns Set rngMyrange = Application.InputBox _ (Prompt:="Select category columns", Type:=8) On Error GoTo 0 'Is a range selected? Exit sub if not selected If rngMyrange Is Nothing Then End Else Exit Do End If Loop With rngMyrange 'with the range just selected 'Need to concatenate the selected columns(row wise) End With rngMyrange.Cells(1, 1) = "Categories" End Sub</code></pre>
Please do not suggest a UDF, I want to do this with macro. I must do this on files before importing them on SQL database, so a macro will be handy. Please ask if I failed to mention anything else.