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

  • Home
  • SEARCH
  • 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 8137091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:58:52+00:00 2026-06-06T10:58:52+00:00

I am trying to write an excel macro/VBA code to adjust a column’s contents

  • 0

I am trying to write an excel macro/VBA code to adjust a column’s contents based off the title of the file. Currently, I have a macro setup to download a csv file based off a URL I type in. The macro automatically formats and names the file. I want to use the first 5 characters of the file’s name/title to automatically format additional cells.

For example, the filename is 48GHY_fjfdkjfe33.RHRH-msadklfjeiojo. I have a column in my file called name+type. I want to combine the “name” row with the title and have it populate the fields. The two images below provide a before and after.

Before Database

After Database

Currently, I have to type in the first 5 characters into a seperate field and then use the:
=”48GHY”&a2 function.

Is there a way to do this in excel/VBA?


The original question was answered, but now I am seeking additional help when trying to put it in a macro. Because it is still the same question, I do not think it warrants another post.

Here is the current macro/VBA I am using. When ever I run this, it just displays #VALUE! in the cell. The only thing different between the two sets of code is that the A and B columns are now J and K.

' Insert Column after name and then rename it name+type

Rows(1).Find("name").Offset(0, 1).EntireColumn.Insert
Rows(1).Find("name").Offset(0, 1).FormulaR1C1 = "name+type"

‘ Freeze the Top Row

Rows("1:1").Select
With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
End With
ActiveWindow.FreezePanes = True

‘Save the file

ActiveWorkbook.Save

‘Add the contents to the name+type column

Range("K2").Select
ActiveCell.FormulaR1C1 = "=LEFT(MID(CELL(""filename"",RC[-1]),SEARCH(""["",CELL(""filename"",RC[-1]))+1,SEARCH(""]"",CELL(""filename"",RC[-1]))-SEARCH(""["",CELL(""filename"",RC[-1]))-1),5)&RC[-1]"
Range("K2").Select
Selection.Copy
Range("K2:K8294").Select
ActiveSheet.Paste

‘ Autofit all Columns

Columns("A:AK").Select
Selection.Columns.AutoFit

End Sub

*One additional comment. I modified the code you provided in the macro, but in each cell after I run it the following code is in column k:

=LEFT(MID(CELL("filename",J2),SEARCH("[",CELL("filename",J2))+1,SEARCH("]",CELL("filename",J2))-SEARCH("[",CELL("filename",J2))-1),5)&J2

*Last note. The file name is being saved as 48GHY_fjfdkjfe33.RHRH-msadklfjeiojo#csv.txt (Could that have anything to do with it?)

  • 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-06T10:58:54+00:00Added an answer on June 6, 2026 at 10:58 am

    Put this in B2

    =LEFT(MID(CELL("filename",A2),SEARCH("[",CELL("filename",A2))+1, SEARCH("]",CELL("filename",A2))-SEARCH("[",CELL("filename",A2))-1),5)&A2

    EDIT

    Explanation

    This formula =CELL("filename",A2) gives you the file name. For example

    C:\Users\Siddharth Rout\Desktop\[Book1.xlsx]Sheet1

    and this formula

    =MID(CELL("filename",A2),SEARCH("[",CELL("filename",A2))+1, SEARCH("]",CELL("filename",A2))-SEARCH("[",CELL("filename",A2))-1)

    takes out just the file name from above to give you Book1.xlsx

    The Left() returns the first character or characters in a text string, based on the number of characters you specify.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write VBA code which works on my Excel sheet. Range(A65536).End(xlUp).Row
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
I'm trying to write an Excel macro using VBA to automate importing CSV text
I'm trying to write a file using VBA. My code is below. It worked
I am trying to write some vba code in Excel to query a table
i am trying to write excel file through erlang. I used the following code
I'm trying to write a code in Excel 2003 VBA (Windows XP) to find
I'm trying to write some dates from one excel spreadsheet to another. Currently, I'm
I am trying to write a VBA script which imports all of the Excel
I am trying to write a macro where changing any column should automatically save

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.