"visual basic excel move column header label" Code Answer's

You're definitely familiar with the best coding language BASIC that developers use to develop their projects and they get all their queries like "visual basic excel move column header label" answered properly. Developers are finding an appropriate answer about visual basic excel move column header label related to the BASIC coding language. By visiting this online portal developers get answers concerning BASIC codes question like visual basic excel move column header label. Enter your desired code related query in the search bar and get every piece of information about BASIC code related question on visual basic excel move column header label. 

visual basic excel move column header label

By Jakes_Bakes_CodeJakes_Bakes_Code on Aug 14, 2020
'===============================================================================
'>> MoveColumnWithHeader(sHeaderName,sColAsLetter)
'===============================================================================
' Cuts the column according to the cell-value and moves it to the column specified
'
' sHeaderName(String):   The header/label of the column to be moved
' sColAsLetter(String):   The letter of the column where you want the column to be
'===============================================================================
Sub MoveColumnWithHeader(sHeaderName As String, sColAsLetter As String)

    Dim sFunct As String: sFunct = "MoveColumnWithHeader"

    Dim bDebugging As Boolean: bDebugging = True
    
    If (bDebugging = True) Then
        Debug.Print Format(DateTime.Now, "hh:mm:ss") & " INFO " & sFunct & "| " _
        & "Running.. [sHeaderName:" & sHeaderName & "][sColAsLetter:" & sColAsLetter & "]"
    End If
        
    '*********************************
    ' VALIDATIONS and declarations
    '*********************************
    '(DECLARATIONS)
    Dim wbInit As Workbook: Set wbInit = ActiveWorkbook
    Dim wsInit As Worksheet: Set wsInit = ActiveSheet
    Dim s_rInit As String: s_rInit = Selection.Address
    
    Dim sErrMsg As String

    Dim rSrcCell As Range
    Dim rSrcCol As Range
    Dim rDestCol As Range
    
    Dim bCheckCase As Boolean
    Dim iInsertShift As Integer
    
    'On Error GoTo ErrHandling
    
    '(SETTINGS/SETUP) - Part A
    
    Application.ScreenUpdating = False
    
    bCaseIsNB = False
    iInsertShift = xlShiftToLeft
    
    Set rSrcCell = wsInit.UsedRange.Find _
        (sHeaderName, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=bCaseIsNB)
    
    '(VALIDATIONS)
    'A) Ensure there is only one letter in sColAsLetter
    'B) Ensure that there is actually text containing sHeaderName
    
    '--(A)
    If (Len(sColAsLetter) <> 1) Then
    
       sErrMsg = sErrMsg & vbNewLine _
           & "sColAsLetter of """ & sColAsLetter & """ is not valid. It can only have one letter"
           
       Err.Raise -1
    
    End If
    
    '--(B)
    If (rSrcCell Is Nothing) Then
    
       sErrMsg = sErrMsg & vbNewLine _
           & "No text found containing the text of """ & sHeaderName & """"
           
       Err.Raise -1
    
    End If
    
    '(SETTINGS/SETUP) - Part B
    Set rDestCol = Range(sColAsLetter & "1").EntireColumn
    Set rSrcCol = rSrcCell.EntireColumn
    
    If (bDebugging = True) Then
        Debug.Print Format(DateTime.Now, "hh:mm:ss") & " INFO " & sFunct & "| " _
        & "Source cell with """ & sHeaderName & """ found " _
        & "at cell [" & rSrcCol.Address & "]"
    End If

    '---------------------------------
    '               WORK
    '---------------------------------
    '1) Ensure that the destination and source columns aren't the same columns
    '2) Cut the column of the header file
    '3) Paste the cut column into its destination
    'Z) Reactivate the initial workbook/worksheet
    
    '--(1)
    If (rSrcCol.EntireColumn.Address = rDestCol.Address) Then

        GoTo Sub_Complete

    End If
    
    '--(2)
    rSrcCol.Cut
    
    '--(3)
    rDestCol.Insert Shift:=iInsertShift
    
Sub_Complete:

    Application.CutCopyMode = False
    
    '--(Z)
    wbInit.Activate
    wsInit.Activate
    Range(s_rInit).Select
    
    '-----------v-----------DEBUG INFO-----------v-----------
    
    If (bDebugging = True) Then
        Debug.Print Format(DateTime.Now, "hh:mm:ss") & " INFO " & sFunct & "| " _
        & "Complete [if not debugging, make bDebugging = false]"
    End If
    
    Application.ScreenUpdating = True
            
    Exit Sub
            
ErrHandling:

    Application.ScreenUpdating = True

    Debug.Print Format(DateTime.Now, "hh:mm:ss") & " INFO " & sFunct & "| " _
        & " -> Failed"
    
    MsgBox _
        Title:="Errors in the function: " & sFunct _
        , Prompt:=Err.Description _
        & vbNewLine & sErrMsg _
        , Buttons:=vbCritical
        
End Sub

Add Comment

1

All those coders who are working on the BASIC based application and are stuck on visual basic excel move column header label can get a collection of related answers to their query. Programmers need to enter their query on visual basic excel move column header label related to BASIC code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about visual basic excel move column header label for the programmers working on BASIC code while coding their module. Coders are also allowed to rectify already present answers of visual basic excel move column header label while working on the BASIC language code. Developers can add up suggestions if they deem fit any other answer relating to "visual basic excel move column header label". Visit this developer's friendly online web community, CodeProZone, and get your queries like visual basic excel move column header label resolved professionally and stay updated to the latest BASIC updates. 

BASIC answers related to "visual basic excel move column header label"

View All BASIC queries

BASIC queries related to "visual basic excel move column header label"

visual basic excel move column header label visual basic excel remove spaces visual basic excel remove scientific notation visual basic excel comma separated list from cells visual basic excel freeze first row visual basic how to declare a variable Custom exception visual basic mid visual basic function visual basic script msgbox visual basic constructor random numbers visual basic visual basic msdos how to repeat an if in visual basic visual basic run command how to assign a variable from a textbox in visual basic visual basic data type visual basic cmd how to dynamically change the font size of a button visual basic VISUAL basic clarity visual basic how to determine if an array already contains an item remove button selection outline visual basic visual basic get mouse position how to remove characters from the end of a string visual basic visual basic how to assign a variable how to round a number in visual basic get status code from webresponse visual basic CType(ex.Response, HttpWebResponse).StatusCode visual basic how to create a dynamic button visual basic non modal message box visual basic how to dynamically change a button to bold visual basic how to prevent dupilcates from being written to an array node-fetch auth basic how to send basic auth using fetch set autorization basic with username and password + resttemplate resttemplate authorization basic curl with basic auth freecodecamp basic algorithm scripting return largest numbers in arrays hello world in basic basic authentication bash how to add basic authentication on haproxy backend server serenity.rs basic bot basic authentication in REST api Dajngo clang cannot detect basic headers API Key Authentication, Basic , Pasword Grant, Client Credentials basic murmur hash function basic input variable what to include in basic C token em vbnet incluido no header da requisição how to download and use visual studio code for chromebook script to add value of 2 coulms of grid and show result in 3rd column

Browse Other Code Languages

CodeProZone