आम तौर पर एक्सेल वर्कशीट में हमारे पास कॉलम शॉर्टकट जोड़ने या डालने के लिए दो अलग-अलग विधियाँ होती हैं, जिनमें से एक पर राइट-क्लिक और इंसर्ट विधि का उपयोग करके किया जाता है, लेकिन VBA में हमें किसी भी कॉलम को जोड़ने के लिए इन्सर्ट कमांड और संपूर्ण कॉलम स्टेटमेंट का उपयोग करना पड़ता है, इसके लिए ट्रिक यह है कि यदि हमें एक कॉलम को सम्मिलित करने की आवश्यकता है तो हम एक कॉलम का संदर्भ देते हैं लेकिन कई कॉलम के लिए हम कई कॉलम का संदर्भ देते हैं।
VBA का उपयोग करके Excel में कॉलम सम्मिलित करें
VBA कोड के भाग के रूप में, हमें अपनी ज़रूरतों को पूरा करने के लिए अपने डेटाशीट में कुछ कॉलम डालने की आवश्यकता हो सकती है। Ctrl + दबाकर, लेकिन VBA कोड के माध्यम से एक नया कॉलम सम्मिलित करने के बारे में कार्यपत्रक में स्तंभ जोड़ना आसान शॉर्टकट कुंजी है । "वीबीए इंसर्ट कॉलम" पर इस लेख में, हम आपको एक्सेल में कॉलम जोड़ने की प्रक्रिया दिखाएंगे और आपको विभिन्न परिदृश्यों के उदाहरण दिखाएंगे।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba_.png.webp)
VBA का उपयोग करके एक्सेल वर्कशीट में कॉलम कैसे डालें?
हम VBA में COLUMNS प्रॉपर्टी और RANGE ऑब्जेक्ट का उपयोग करके कॉलम डाल सकते हैं। आपको नया कॉलम डालने के लिए कॉलम और रेंज ऑब्जेक्ट की आवश्यकता क्यों होनी चाहिए।
एक नया कॉलम सम्मिलित करने के लिए, हमें यह बताने की आवश्यकता है कि हमें किस कॉलम को सम्मिलित करने की आवश्यकता है, बिना यह बताए कि हमें किस कॉलम में वीबीए तर्क को समझ सकता है।
उदाहरण के लिए, यदि आप स्तंभ B के बाद कॉलम सम्मिलित करना चाहते हैं, तो आप इस तरह कोड का निर्माण कर सकते हैं।
कॉलम ("C")
नोट: कारण है कि मैंने एक कॉलम डालने के लिए C का उपयोग किया है क्योंकि चयनित सेल को दाईं ओर स्थानांतरित किया जाएगा।
कॉलम निर्दिष्ट होने के बाद, हमें "संपूर्ण कॉलम" संपत्ति तक पहुंचने की आवश्यकता है।
कॉलम ("C")। EntireColumn
फिर हमें "इन्सर्ट" विधि चुनने की आवश्यकता है।
कॉलम ("C")। EntireColumn.Insert
यह कॉलम C के बाद कॉलम को सम्मिलित करेगा, और मौजूदा कॉलम C को D पर ले जाया जाएगा।
उदाहरण # 1 - VBA में रेंज ऑब्जेक्ट का उपयोग करके कॉलम सम्मिलित करें
अब, RANGE ऑब्जेक्ट का उपयोग करके कॉलम डालने का तरीका देखें। इसके लिए, उदाहरण के लिए नीचे दिए गए डेटा पर विचार करें।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__2.png.webp)
अब मैं A कॉलम के बाद VBA कॉलम डालना चाहता हूं, कोड बनाने के लिए नीचे दिए गए चरणों का पालन करें।
चरण 1: उप प्रक्रिया शुरू करें।
चरण 2: ओपन रेंज ऑब्जेक्ट।
कोड:
उप ColumnInsert_Example1 () श्रेणी (अंतिम उप)
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__3.png.webp)
चरण 3: अब डबल-कोट्स में कॉलम का उल्लेख करें ।
कोड:
उप ColumnInsert_Example1 () रेंज ("B: B") समाप्ति उप
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__4.png.webp)
चरण 4: अब संपूर्ण कॉलम संपत्ति चुनें।
कोड:
उप ColumnInsert_Example1 () श्रेणी ("B: B")
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__5.png.webp)
चरण 5: संपूर्ण कॉलम की संपत्ति का चयन करने के बाद, "इंसर्ट" विधि चुनें।
कोड:
उप कॉलमइन्मेंट_एक्सप्ल १ () रेंज ("बी: बी")। EntireColumn.ins अंत उप
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__6.png.webp)
अब आपका कोड कुछ इस तरह दिखता है।
कोड:
उप कॉलमइन्स्टॉर_Example1 () रेंज ("B: B")। EntireColumn.Insert समाप्ति उप
कोड चलाएँ। यह नया बी कॉलम डालेगा।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba_.gif)
उदाहरण # 2 - कई कॉलम सम्मिलित करें
For example, if you want to insert two new columns after column A, then we need to mention two column addresses.
Code:
Sub ColumnInsert_Example1() Range("B:C").EntireColumn.Insert End Sub
The above code will insert two columns after column A.
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__2.gif)
Example #3 - With “Insert” Only Method
We can insert a new column by using “Insert” the only method without accessing the Entire Column property. For this, let’s understand the “insert” method syntax.
Expression.Insert((Shift),(Copy Origin))
(Shift): When we insert the new column, whether we need the columns to shift to the right side or to shift to the downside in case of rows. Here we can use two options, “xlToRight” and “xlDownTo”
(Copy Origin): This will specify the format for the newly inserted column. Whether you need the format from the left side of the column or from the above cells. Here we can use two options “xlFormatFromLeftOrAbove” and “xlFormatFromRightOrBelow”.
Below is the example code for you.
Sub ColumnInsert_Example1() Range("B:B").Insert Shift:=xlToRight, Copyorigin:=xlFormatFromLeftOrAbove End Sub
Example #4 - Insert Columns Using COLUMNS Property in VBA
We have seen how to VBA insert columns using the RANGE object; now, we will show we can insert columns using the “COLUMNS” property.
Open the COLUMNS property.
Code:
Sub ColumnInsert_Example2() Columns( End Sub
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__7.png.webp)
We can specify the column in two ways here. One is using as usual alphabetic references, and another one is using column numbers.
If you want to insert the column after column A, then the code will be COLUMNS(“B”). If you are using numerical reference, then the code will be COLUMNS(2).
Code:
Sub ColumnInsert_Example2() Columns("B"). End Sub
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__8.png.webp)
Now the problem for you arises because when we use COLUMNS property, we don’t get to access the IntelliSense list.
Code:
Sub ColumnInsert_Example2() Columns("B").Entir End Sub
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__9.png.webp)
Here we need to sure of what we are doing. So this is the reason I have showed you the RANGE object first.
Code:
Sub ColumnInsert_Example2() Columns("B:B").EntireColumn.Insert End Sub
Example #5 - Insert Alternative Columns
Assume you have the data like the below image.
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__10.png.webp)
If you want to insert new columns after every alternate row, then we need to use VBA loops. The below code it tailor-made the code for you.
Code:
Sub ColumnInsert_Example3 () Dim k As Integer Columns (2) .Select for k = 2 to k ActiveCell.EntireColumn.Insert ActiveCell.Offset (0, 2) .Select Next k End Sub
यह इस तरह से कॉलम डालेगा।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__3.gif)
उदाहरण # 6 - सेल वैल्यू के आधार पर कॉलम डालें
हम सेल वैल्यू के आधार पर एक कॉलम भी डाल सकते हैं। उदाहरण के लिए, नीचे दिए गए डेटा को देखें।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__11.png.webp)
यहां मैं कॉलम को सम्मिलित करना चाहता हूं अगर पहली पंक्ति का सेल मान "वर्ष" है, और नए कॉलम डालने के बाद मेरा डेटा इस तरह होना चाहिए।
![](https://cdn.know-base.net/6534104/vba_insert_columns_how_to_insert_column_in_excel_worksheet_with_vba__4.gif)
इस कार्य को करने के लिए नीचे दिए गए कोड का उपयोग करें।
कोड:
Sub ColumnInsert_Example4 () Dim k As Integer Dim x As Integer x = 2 For k = 2 To k = 2 to 12 If Cells (1, x) .Value = "वर्ष" फिर कक्ष (1, x) .EireireColumn.Insert x = x + 1। अंत अगर x = x + 1 अगला k अंत उप
आप इस VBA इन्सर्ट कॉलम एक्सेल को यहाँ डाउनलोड कर सकते हैं। VBA कॉलम कॉलम एक्सेल टेम्प्लेट सम्मिलित करें