Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:59:24+00:00 2026-06-13T00:59:24+00:00

I want to execute the following VBA code for each worksheet at once in

  • 0

I want to execute the following VBA code for each worksheet at once in an Excel file:

Sub sample_code()    
    Columns("B:B").Select
    Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("A:A,D:J").Select
    Range("D1").Activate
    Selection.Delete Shift:=xlToLeft
    Columns("F:P").Select
    Selection.Delete Shift:=xlToLeft
    Columns("A:E").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 30.86
    Range("A1:E1").Select
    Selection.Font.Bold = True
End Sub

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:59:25+00:00Added an answer on June 13, 2026 at 12:59 am

    Like this:

    Sub sample_code()
        Dim ws As Worksheet
    
        For Each ws In Worksheets
            With ws
                .Columns("B:B").Replace What:=" ", Replacement:="", LookAt:=xlPart, _
                    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                    ReplaceFormat:=False
                .Range("A:A,D:J").Delete Shift:=xlToLeft
                .Columns("F:P").Delete Shift:=xlToLeft
                .Columns("A:E").EntireColumn.AutoFit
                .Columns("B:B").ColumnWidth = 30.86
                .Range("A1:E1").Font.Bold = True
            End With
        Next ws
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute python code from C# with following code. static void Main(string[]
I want the following code to execute when the myString is having either of
I want to execute the following query using Subsonic: SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory] While
I want to execute following code on button click but the follwing code executes
I want to execute an ant build through java code. I use the following
When I execute the following code: File f = getFile(); String absPath = f.getAbsolutePath()
I want to execute a following code. #include <iostream> #include <thread> void output() {
I want ot execute the following commands using batch file: 1.ftp 127.0.0.1 2.USERNAME 3.PASSWORD
I simply want to execute the following Mysql statement SET @a = 1;SELECT @a;
Following code gets executed whenever I want to persist any entity. Things seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.